动态更改 animateCamera 俯仰和缩放属性不起作用

2023-12-13

使用 useState 动态更改 animateCamera 俯仰和缩放属性不起作用

                onLayout={() => {
                    map.current.animateCamera({
                        center: { latitude: location?.coords?.latitude, longitude: location?.coords?.longitude },
                        zoom: zoomLevel,
                        heading: 50,
                        pitch: pitchLevel,
                        altitude: 5,
                    })
                }}

我发现onlayout不太适用于转换。

So here's all of the undocumented or buggy behavior I've encountered with onLayout and .measure so far:

onLayout doesn't get called in some conditions (seemingly when an element is moved by a parent resizing)
the measure returns undefined on android unless there's an onLayout or collapsible: false on the view
onLayout doesn't take transforms into account, it returns the "internal" size of the view not the size displayed on the screen
onLayout doesn't fire for animations of transforms (which is pretty much all animations since only transforms and opacity can use native driver) -- that's this issue
measure returns different values for width and height than onLayout. It returns scaled values if any parent is scaled as opposed to the raw values. Docs suggest the opposite.
onLayout Will return wrong/random values during component mount in some (maybe all?) cases if the view or any parent is being animated.
It's because layout process is not involved in transformations at all. Actually Animated can't change any properties that can change layout of the component tree.

我发现这个方法https://reactnative.dev/docs/direct-manipulation如果我找到解决方案,我会给出一个片段


我认为你应该使用钩子(useEffect)将地图动画化到该区域。就我而言,我从 GoogleAutoPlaces 获取新位置 API 。我正在坐标变量中接收 latlng 对象。在这里你 可以添加坐标变量作为依赖项,当您的位置 会改变它会自动将地图动画化为新的 地点。 useEffect(() => { mapref?.current?.animateToRegion(coordinate, 1000); }, [coordinate]);

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

动态更改 animateCamera 俯仰和缩放属性不起作用 的相关文章

随机推荐