React Native 鍵盤將一切推高,我無法控制
P粉466643318
P粉466643318 2024-03-30 21:40:43
0
1
458

當鍵盤打開時,我只希望評論輸入向上移動,但所有內容都會向上移動

export default function DetailsPage({ route, navigation }) {
  const { title, detail, degree } = route.params;
  const [comment, setComment] = useState("")
  return (
    <ScrollView style={{flex:1}}>
    <View style={{ height: responsiveHeight(100), paddingTop: StatusBar.currentHeight }} >
    
      <ImageBackground blurRadius={0} source={require('../assets/bgg.jpg')} resizeMode="cover" >
        <View style={{ height: responsiveHeight(35), borderWidth: 1 }}>
          <View style={{ width: responsiveWidth(80), height: responsiveHeight(15), justifyContent: 'space-around', alignSelf: 'center', marginTop: 40 }}>
            <Text style={{ fontFamily: 'Inter-Bold', fontSize: 18 }}>Example</Text>
            <Text numberOfLines={3} style={{ fontFamily: 'Roboto-Medium' }}></Text>
          </View>
        </View>
      </ImageBackground>


      <View style={{ paddingHorizontal: responsiveWidth(10), paddingVertical: responsiveWidth(10), height: responsiveHeight(65), borderWidth: 1, borderTopLeftRadius: 40, borderTopRightRadius: 40, marginTop: -responsiveHeight(10), backgroundColor: 'white' }}>
        <View style={{ height: responsiveHeight(50), borderWidth: 1 }}>
          <CommentCard></CommentCard>
        </View>
      </View>
      
      <KeyboardAvoidingView >
        <View style={{height:responsiveHeight(10),backgroundColor:'white'}}>
          <InputComp></InputComp>
        </View>
      </KeyboardAvoidingView>
      
    </View>
    </ScrollView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

我嘗試了“softwareKeyboardLayoutMode”:“pan”,解決方案 我到處嘗試了 KeyboardAvoidingView 和 KeyboardVerticalOffset 但找不到解決方案 我嘗試了帶或不帶鍵盤的滾動視圖避免視圖

P粉466643318
P粉466643318

全部回覆(1)
P粉801904089

您可以嘗試在程式碼中加入這三件事。

  1. 在 InputComp 元件周圍新增一個 KeyboardAvoidingView。

  2. 將 KeyboardAvoidingView 的行為屬性設定為「padding」。

  3. 將 KeyboardAvoidingView 的樣式屬性設為 {height: 響應式高度(10),背景顏色:'白色'}。

    export default function DetailsPage({ route, navigation }) {
    const { title, detail, degree } = route.params;
    const [comment, setComment] = useState("")
    return (
    
    
          
    
      
        Example
        
      
      
      
      
        
          
        
      
    
      
        
      
    
    
    
    );
    }
    
      const styles = StyleSheet.create({
      container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
    },
    });
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板