可touch 的Opacity组件不工作,我不知道原因

第一个组件App.tsx

function App(): JSX.Element {
  const [focuseSubject, setFocusSubject] = useState(null)
  
  return (
    <View style={styles.container}>
      { focuseSubject ? <Text>{focuseSubject} </Text> : <Focus addSubject={setFocusSubject} /> }
      
      <Text style={ {color: 'white'} }>{ focuseSubject }</Text>
    </View>
  );
}

第二个组件Focus.tsx

function Focus({ addSubject }) {
    const [tempItem, setTempItem] = useState('');
    return (
      <View style={styles.container}>
        <View style={styles.titleContainer}>
          <Text style={styles.title}>What would you lie to focus on?</Text>
          <View style={styles.inputContainer}>
            <TextInput
              style={styles.textInput}
              onSubmitEditing={(event) => {
                setTempItem(event.nativeEvent.text);
              }}
            />
            <RoundedButton
              title="+"
              size={50}
              onPress={() => {
                addSubject(tempItem);
              }}
            />
            {/* <Text>{ tempItem }</Text> */}
          </View>
        </View>
      </View>
    );
}

第三个组成部分

function RoundedButton({style = {}, textStyle = {}, size = 125, ...props}) {
  return (
    <TouchableOpacity style={[styles(size).radios, style]}>
      <Text style={[styles(size).text, textStyle]}>
        {props.title}
      </Text>
    </TouchableOpacity>
  );
}

如果我加onSubmitEditing={addSubject(event.nativeEvent.text)}就行了,但我想用这个按钮.

注:TouchableOpacity imported from react-native

推荐答案

你需要通过TouchableOpacityonPress个props ,从RoundedButton:

function RoundedButton({style = {}, textStyle = {}, size = 125, ...props}) {
  return (
    <TouchableOpacity style={[styles(size).radios, style]} onPress={props.onPress}>
      <Text style={[styles(size).text, textStyle]}>
        {props.title}
      </Text>
    </TouchableOpacity>
  );
}

React-native相关问答推荐

Appcenter构建失败错误号::EEXIST -文件存在于syserr_fail2_in

try 使用JWT-DECODE解码令牌时出错

react 在顶部选项卡导航中传递本机数据

如何修复 React Native 中任务:app:processDebugManifest的执行失败?

react native条件渲染

React-native android 样式化 textInput

TypeError:undefined is not an object(判断'navigator.geolocation.requestAuthorization')

在 CircleCI 上 ReactNative 0.59.x build fails on CircleCI with exit value 137

Soundcloud API /stream 端点给出 401 错误

React-Native Android - 找不到 com.android.tools:common

FlatList contentContainerStyle -> justifyContent: 'center' 导致滚动问题

使用 React Native 打开 iOS iPad 模拟器

如何在 ubuntu 上安装 facebook watchman?

如何在 React Native 中获取电话号码?

axios 的网络错误和react-native

如何在 Text 中围绕 Text 包裹 TouchableOpacity?

如何在 React Native Android 中设置按钮的高度

在 React Native ScrollView 中检测滚动结束,对齐页面

Android 是否支持 React Native 的 LayoutAnimation?

com.facebook.react.bridge.readablenativemap 不能转换为 java.lang.string