简体   繁体   English

是否可以将动画 setValue 与 useNativeDriver 一起使用?

[英]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-reanimatedreact-native-gesture-handler

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 React Native Animated 中使用 useNativeDriver 时出错 - Error when use useNativeDriver in React Native Animated 动画:`useNativeDriver` 未指定 ReactNativeBase 输入问题 - Animated: `useNativeDriver` was not specified issue of ReactNativeBase Input 什么时候在 React Native 中使用 useNativeDriver? - When to use useNativeDriver in React Native? React Native Animated with useNativeDriver - _reactNative.Animated.event(...) 不是函数 - React Native Animated with useNativeDriver - _reactNative.Animated.event(...) is not a function 如何在选项 useNativeDriver 设置为 true 的情况下获取动画值的当前值? - How to get the current value of animated values with option useNativeDriver set to true? 警告动画:未指定`useNativeDriver`。 React-Native 62.2 - warning Animated: `useNativeDriver` was not specified. React-Native 62.2 React Native 动画 setValue() 问题? - React Native Animated setValue() problem? 如何解决“动画:不支持`useNativeDriver`,因为缺少本机动画模块。” 在反应导航? - How to resolve "Animated: `useNativeDriver` is not supported because the native animated module is missing." in react-navigation? 动画:未指定 `useNativeDriver`。 这是一个必需选项,必须在 React Native 上显式设置为 `true` 或 `false - Animated: `useNativeDriver` was not specified. This is a required option and must be explicitly set to `true` or `false on React Native 动画:未指定`useNativeDriver`。 这是一个必需选项,必须明确设置为 `true` 或 `false` #31 - Animated: `useNativeDriver` was not specified. This is a required option and must be explicitly set to `true` or `false` #31
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM