gpt4 book ai didi

react-native - 将 onPress 函数绑定(bind)到 View

转载 作者:行者123 更新时间:2023-12-02 03:38:49 26 4
gpt4 key购买 nike

我想将 onPress 事件绑定(bind)到 TextView 的一部分,而不使用 TouchableOpacity 或 TouchableHighlight,因为它们会用新行中断文本。

有没有办法将其直接绑定(bind)到React-native中的Text元素?

最佳答案

import React,{Component} from 'react';
import { View, Text, Alert} from 'react-native';

export default class SliderContainer extends Component {

render() {
return (
<View style={{marginTop: 50}}>
<Text>
{`TextPartOne
`}
<Text onPress={() => Alert.alert(
'Alert Title',
'My Alert Msg',
[
{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: false }
)}>
{`Nested text to press`}
</Text>
{`
TextPartTwo`}
</Text>
</View>
);
}
}

你可以尝试this snack .

关于react-native - 将 onPress 函数绑定(bind)到 <Text> View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49344678/

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