reactnativecn / react-native-website

React Native 中文网
https://reactnative.cn
MIT License
216 stars 327 forks source link

Modal 组件中使用TextInput,Android 键盘不能自动弹起 #709

Closed hmyjyghh closed 10 months ago

hmyjyghh commented 1 year ago

Modal 组件中使用TextInput,Android 键盘不能自动弹起

<Modal statusBarTranslucent={true} transparent={true} animationType="none" visible={show}>
           <TextInput
                ref={textInputRef}
                placeholderTextColor={'#ccc7c7'}
                autoFocus={true}
                style={styles.input}
                multiline={true}
                numberOfLines={3}
                placeholder={$t('app_share_idea')}
                maxLength={200}
                selectionColor={appPrimary}
                onChangeText={text => {
                  changeValue(text)
                }}
              />
</Modal>

Rn环境/版本信息

预期结果

sunnylqm commented 1 year ago

ref + useEffect + setTimeout

hmyjyghh commented 1 year ago

ref + useEffect 用了 , setTimeout 没用

useEffect(() => {
    textInputRef.current && textInputRef.current.focus()
  }, [show])

<TextInput ref={textInputRef}
hmyjyghh commented 1 year ago

用setTimeout 可以了

useEffect(() => {
    setTimeout(() => {
      textInputRef.current && textInputRef.current.focus()
    }, 100)
  }, [show])
github-actions[bot] commented 10 months ago

👋 Hey there, it looks like there has been no activity on this issue in the last 90 days. Has the issue been fixed, or does it still require the community attention? This issue will be closed in the next 7 days if no further activity occurs. Thank you for your contributions.