Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
我用的是RN 0.57.2,在iOS上,只是最简单的渲染MapView,多次重复进入,有的时候显示正确,有的时候会有很大的偏移。
看了下Issue,提到的实际在iOS上的frame发生了变化,我在AMapView.m中拦截了
setFrame
和setBounds
,结果如下: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