【发布时间】:2021-11-10 00:33:19
【问题描述】:
我有两个简单的组件:
const AddUserInfo = () => {
const scroll = useRef(null)
return (
<View style={ styles.container }>
<View style={ styles.slider }>
<ScrollView
ref={scroll}
horizontal= {true}
snapToInterval= {width}
decelerationRate= "fast"
showsHorizontalScrollIndicator= {false}
bounces= {false}
>
<Animated.View style={{flex: 1, width: width }}>
<Slider1 style={{flex: 4}}/>
<Animated.View style={{flex: 2, justifyContent: 'flex-end', alignItems: 'center'}}>
<TouchableOpacity style={styles.buttonCircle} onPress={() => {
if(scroll.current) {
scroll.current.scrollTo({ x: width, y: 0, animated: true });
}
}}/>
</Animated.View>
</Animated.View>
还有这个:
const Slider1 = () => {
const [pseudo, setPseudo] = useState("")
return (
<Animated.View style={{flex: 4}}>
<TextInput
mode="outlined"
value={pseudo}
label="Pseudo"
placeholder="Pseudo"
onChangeText= {(pseudo) => setPseudo(pseudo)}
/>
</Animated.View>
)
}
为了保持一切干净,它们位于不同的文件中。 我在这里要做的是从 Slider1 组件中获取“伪”值,并能够将其用于 AddUserInfo 组件。
最好的方法是什么?
感谢您的帮助!
【问题讨论】:
标签: javascript react-native components