当我尝试在组件中初始化状态时,它给我SyntaxError:出现意外的令牌
constructor(props) {
super(props);
this.state = {
isFromDatePicked = false,
isToDatePicked = false,
markedDates = {},
}
}
Run Code Online (Sandbox Code Playgroud)
isFromDatePicked = false线。我还尝试在构造函数外部初始化状态,但也无法正常工作。
另外,当我删除状态初始化以测试代码时,它在以下位置也给了我同样的错误
let markedDates = { ...this.state.markedDates };
let [_markedDates, range] = this.setupMarkedDates(this.state.fromDate, this.state.toDate, markedDates);
if (range >= 0) {
this.setState({ isFromDatePicked: true, isToDatePicked: true, markedDates = _markedDates });
Run Code Online (Sandbox Code Playgroud)
markedDates = _markedDates 线。
我不知道为什么会抛出这样的错误。谢谢您的任何帮助。
我试图在下面的示例中完成非常相似的动画。
borderWidth我的方法是这样的:获取语音音量数据,使用 shareValue将其附加到视图中react-native-reanimated。但是,由于borderWidth将自身附加到 的内部View,因此可视化效果如下例所示:
下面你可以找到我的代码,
相关状态的初始化react-native-reanimated。
const voiceVolumeMeter = useSharedValue(0);
const voiceVolumeMeterStyles = useAnimatedStyle(() => {
return {
borderWidth: voiceVolumeMeter.value,
};
});
Run Code Online (Sandbox Code Playgroud)
将体积数据附加到voiceVolumeMeter参数:
voiceVolumeMeter.value = withSpring(55 + e.currentMetering!, {
stiffness: 90,
velocity: 12,
mass: 0.5,
});
Run Code Online (Sandbox Code Playgroud)
适用animatedStyle于View
<Animated.View style={[styles.volumeMeterContainer, voiceVolumeMeterStyles]}>
<View style={styles.recorderCircle}>
<Text style={styles.audioRecorderTimer}>{recorderState.duration}</Text>
</View>
</Animated.View>
Run Code Online (Sandbox Code Playgroud)
上面代码示例使用的样式:
recorderCircle: {
width: 280,
height: 280,
borderRadius: 150,
borderColor: Colors.DUSTY_ORANGE,
justifyContent: 'center',
alignItems: 'center',
},
volumeMeterContainer: {
width: 290, …Run Code Online (Sandbox Code Playgroud) javascript typescript react-native react-native-reanimated-v2