Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:iOS上地图中心点经常不能对准的问题。 #465

Merged
merged 1 commit into from
Jan 15, 2019
Merged

Fix:iOS上地图中心点经常不能对准的问题。 #465

merged 1 commit into from
Jan 15, 2019

Conversation

gxsshallot
Copy link

@gxsshallot gxsshallot commented Dec 28, 2018

我用的是RN 0.57.2,在iOS上,只是最简单的渲染MapView,多次重复进入,有的时候显示正确,有的时候会有很大的偏移。

看了下Issue,提到的实际在iOS上的frame发生了变化,我在AMapView.m中拦截了setFramesetBounds,结果如下:

  • setFrame:一般调用两次。一次是AMapViewManager.m中的view方法,调用new初始化时,传入的frame(0, 0, 0, 0),记为A。另一次是frame为屏幕宽高的两倍,记为B。
  • setBounds:调用一次,是RN部分设置的实际宽高,记为C。

可以知道:setFrame设置的长宽有问题,setBounds设置的是正确的。

A是第一次调用,而B和C的调用顺序不确定。有时候B先执行,则结果正确;有时候C先执行,则结果异常。个人猜测是两个线程同时设置导致的,B是高德SDK自动适配的设置线程,C是RN的处理线程。

于是我在setBounds中加上标识,一旦其被调用过,则setFrame就无法调用了。这样可以保证A是始终生效的,C如果调用过,则B无法生效。经测试,解决了问题,并且通过setState动态改变视图位置和宽高依旧有效。

相关Issue:#218 #251 #419 #435

@qiuxiang
Copy link
Owner

这个修改看起来更靠谱,不过我得过段时间,忙完今年的工作才有时间合并

@chriiess
Copy link

这个方案不错,测试已经通过

@hydraZty
Copy link

不知能否解决 InfoWindow onPress 失效问题,元旦回来测

@wei63w
Copy link

wei63w commented Jan 2, 2019

666 确实没问题

@qiuxiang qiuxiang merged commit d63ce49 into qiuxiang:master Jan 15, 2019
@wei63w
Copy link

wei63w commented Jan 16, 2019

@qiuxiang 老哥 什么时候更新到npm 上啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants