[英]Is it possible to use animated setValue with useNativeDriver?
I am translating views to follow a move gesture, with least possible latency.我正在翻译视图以跟随移动手势,尽可能减少延迟。
I am investigating a couple of options and one of which is - if possible - to send the setValue action to UI thread, rather than the JS thread.我正在研究几个选项,其中一个是 - 如果可能的话 - 将 setValue 操作发送到 UI 线程,而不是 JS 线程。
Even though in the documentations it is stated that the Animated.timing, Animated.spring, etc type of functions can be offloaded to the UI thread with useNativeDriver: true
directive, there is no reference - at least that I could have found - on if it is possible to send the direct setValue action to the UI thread or not.即使在文档中声明 Animated.timing、Animated.spring 等类型的函数可以使用
useNativeDriver: true
指令卸载到 UI 线程,但没有参考 - 至少我可以找到 - 如果是否可以将直接 setValue 操作发送到 UI 线程。
My question is;我的问题是; is it possible to use animated setValue with useNativeDriver and how if possible.
是否可以将动画 setValue 与 useNativeDriver 一起使用,以及如何使用。
Below is the rough example of the code that I am using:下面是我正在使用的代码的粗略示例:
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {};
this.spaceAnimatedTranslations = new Animated.ValueXY();
this._animatedStyle = {
transform: [
{ translateX: this.spaceAnimatedTranslations.x },
{ translateY: this.spaceAnimatedTranslations.y }
]
};
}
onSpaceMove(event) {
this.spaceAnimatedTranslations.setValue({x: event.nativeEvent.translationX, y: event.nativeEvent.translationY});
}
render(){
return <PanGestureHandler
key={`test`}
onGestureEvent={e => this.onSpaceMove(e)}>
<Animated.View
ref={ref => {
this.testAnimatedView = ref;
}}
style={[this._animatedStyle]}>
<View style={styles._box_content}>
{someContent}
</View>
</Animated.View>
</PanGestureHandler>
}
}
You have to use Animated.event
to do the mapping directly in native thread.您必须使用
Animated.event
直接在本机线程中进行映射。 See Tracking gestures .请参阅跟踪手势。 Other possibility would be to use
react-native-reanimated
with react-native-gesture-handler
.其他可能性是使用
react-native-reanimated
和react-native-gesture-handler
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.