gpt4 book ai didi

javascript - 动画 : `useNativeDriver` was not specified issue of ReactNativeBase Input

转载 作者:行者123 更新时间:2023-12-03 07:34:19 25 4
gpt4 key购买 nike

我今天(2020 年 4 月 3 日)创建了一个新的 react-native 项目并添加了一个原生基础。然后我尝试使用 float 标签添加输入。它给出了一条警告消息:动画:useNativeDriver未指定。这是一个必需选项,必须明确设置为 truefalse .如果我删除了 float 标签属性或将其更改为stackedLabel,则警告消失了。出现此警告时,onChangeText没有被调用。
Warning message
组件文件

import React from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
View,
} from 'react-native';

import {Input, Item, Label} from 'native-base';

import {Colors} from 'react-native/Libraries/NewAppScreen';

declare var global: {HermesInternal: null | {}};

const App = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<View style={styles.body}>
<Item floatingLabel>
<Label>Test</Label>
<Input onChangeText={text => console.log(text)} />
</Item>
</View>
</ScrollView>
</SafeAreaView>
</>
);
};
包.json
{
"name": "formtest",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"native-base": "^2.13.12",
"react": "16.11.0",
"react-native": "0.62.0"
},
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^1.0.0",
"@types/jest": "^24.0.24",
"@types/react-native": "^0.62.0",
"@types/react-test-renderer": "16.9.2",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.58.0",
"react-test-renderer": "16.11.0",
"prettier": "^2.0.2",
"typescript": "^3.8.3"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}

最佳答案

只需添加 useNativeDriver: true到动画配置。

const [animatePress, setAnimatePress] = useState(new Animated.Value(1))

const animateIn = () => {
Animated.timing(animatePress, {
toValue: 0.5,
duration: 500,
useNativeDriver: true // Add This line
}).start();
}
更新
解决方案:
正如警告所说,我们需要指定 useNativeDriver显式选项并将其设置为 truefalse .
1-动画方法
引用 Animated doc ,具有动画类型或合成功能,例如 Animated.decay() , Animated.timing() , Animated.spring() , Animated.parallel() , Animated.sequence() , 指定 useNativeDriver .
Animated.timing(this.state.animatedValue, {
toValue: 1,
duration: 500,
useNativeDriver: true, // Add this line
}).start();
2- 动画组件 Animated使用上述包装器导出以下动画组件:
  • Animated.Image
  • Animated.ScrollView
  • Animated.Text
  • Animated.View
  • Animated.FlatList
  • Animated.SectionList

  • 使用 Animated.event() 时, 添加 useNativeDriver: false/true到动画配置。
    <Animated.ScrollView
    scrollEventThrottle={1}
    onScroll={Animated.event(
    [{ nativeEvent: { contentOffset: { y: this.state.animatedValue } } }],
    { useNativeDriver: true } // Add this line
    )}
    >
    {content}
    </Animated.ScrollView>

    关于javascript - 动画 : `useNativeDriver` was not specified issue of ReactNativeBase Input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61014661/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com