如何修复每当我在 Expo React-Native 中使用 KeyboardAwareView 或 React-native-keyboard-aware-scroll-view 时显示的白色键盘空间?

2024-01-10

我在创建应用程序时使用 Expo-react-native,但使用 KeyboardAvoidingView 和其他键盘包 (react-native-keyboard-aware-scroll-view) 在屏幕底部显示空白。我该如何解决? (https://i.stack.imgur.com/1c0M6.jpg https://i.stack.imgur.com/1c0M6.jpg)已尝试 KeyboardAvoidingView 和 react-native-keyboard-aware-scroll-view 但问题仍然存在

       import React, {Component} from 'react';
       import {StyleSheet,
       ScrollView,
       Text,ActivityIndicator,
       TouchableOpacity,
       TextInput,
        View,
        StatusBar,
       ImageBackground,
        KeyboardAvoidingView} from 'react-native';

       import { createStackNavigator, createAppContainer } from 'react- 
        navigation';
        import { KeyboardAwareView } from 'react-native-keyboard-aware- 
        view';
        import { AsyncStorage } from 'react-native';

        export default class LoginForm extends Component {
        render() {
         return (
           <KeyboardAwareView contentContainerStyle={{flex: 1}} animated={true}>
      <View style={styles.container}>
      <ScrollView style={{flex: 1}}>
    <StatusBar
      backgroundColor="transparent"
      barStyle="default"
      translucent={true}
    />
        <ImageBackground style={{width: "100%",height: "100%",resizeMode: "cover"}} source={require('./bg.jpg')}>
        <View style={styles.title}>
          <Text style={styles.big}>AgroSight</Text>
          <Text style={styles.small}>An agro based app for farmers and persons</Text>
          {
          this.state.ActivityLoader ? <ActivityIndicator color='#FFF' size='large' style={styles.Activity} />: null
        }
        </View>

        <View style={styles.formContainer}>
          <ScrollView style={{flex:1}}>
              <TextInput
              style={styles.input}
              placeholder="Email Address"
              returnKeyType="next"
              keyboardType="email-address"
              autoCapitalize="none"
              autoCorrect={false}
              onSubmitEditing = {() => this.passwordInput.focus()}
              placeholderTextColor="rgba(255,255,255,.7)"
              name="email"
              onChangeText={(TextInput) => this.setState({userEmail: TextInput})}

            />
            <TextInput
              style={styles.input}
              placeholder="Password"
              returnKeyType="go"
              secureTextEntry
              ref={(input) => this.passwordInput = input}
              placeholderTextColor="rgba(255,255,255,.7)"
              name="password"
              onChangeText={(TextInput) => this.setState({password: TextInput})}
            />

            <TouchableOpacity style={styles.buttonContainer} onPress={ this.LoginUser }>
              <Text style={styles.buttonText}>LOG IN</Text>
            </TouchableOpacity>
            </ScrollView>
        </View>

        <View style={styles.bottomRow}>
          <Text style={styles.signupText}> Don't have account ?
              <Text style={styles.reg} onPress={() => this.props.navigation.navigate('RegisterScreen')}>REGISTER HERE</Text>
          </Text>
        </View>
        </ImageBackground>
          </ScrollView>
            </View>
    </KeyboardAwareView>
     );
   }
 }

  const styles = StyleSheet.create({
    container: {
     flex: 1,
    },
    title: {
     marginTop: 20,
     alignItems: "center",
     justifyContent:"center",
      height: "30%"
     },
big: {
  marginTop: 20,
  fontSize: 50,
  color: "white",
  alignItems:"center",
  fontWeight:"bold",
},
small: {
  marginTop: 4,
  fontSize: 20,
  color:"#FFF",
  fontWeight:"bold",
  opacity: .8
},
bottomRow: {
  padding: 20,
  justifyContent: "center",
  paddingVertical: 20
},
signupText: {
  fontSize: 21,
  color:"#FFF",
  fontWeight: "700",
  alignItems: "center"
},
 reg: {
   color: "#FED81E",
   alignItems: "center"
 },
 formContainer:{
   padding: 20,
   flex:1
 },
  input: {
    height: 50,
    backgroundColor: "green",
    color: "#FFF",
    paddingHorizontal: 10,
    marginBottom: 10,
    borderRadius: 7,
    fontSize: 20,
    paddingVertical: 10
  },
buttonContainer: {
  backgroundColor: "#FFF",
  paddingVertical: 15,
  borderRadius: 8
},
buttonText: {
  textAlign: 'center',
  color:"green",
  fontWeight: '700',
  fontSize: 27
},
Activity:{
  position: 'absolute',
  left: 0,
  right: 0,
  top: 150,
  bottom: 0,
  alignItems: 'center',
  justifyContent: 'center',
  zIndex: 999
   },
 });

我在 React Native ios 中检查并修改了你的代码。以下代码可能对您有帮助。

    import React, {Component} from 'react';
    import {StyleSheet,
    ScrollView,
    Dimensions,
    Text,ActivityIndicator,
    TouchableOpacity,
    TextInput,
    View,
    StatusBar,
    ImageBackground,
    KeyboardAvoidingView} from 'react-native';
    let {height, width} = Dimensions.get('window');


    export default class LoginForm extends Component {
    render() {
     return (
     <KeyboardAvoidingView behavior={"padding"} enabled  style= . 
     {{flexGrow:1,height:'100%'}}>
        <ScrollView bounces={false} >
            <StatusBar
            backgroundColor="transparent"
            barStyle="default"
            translucent={true}
            />
            <ImageBackground style={{width: "100%",height: height}} source={require('./bg.jpg')}>
            <View style={{flex:1}}>
                    <View style={styles.title}>
                        <Text style={styles.big}>AgroSight</Text>
                        <Text style={styles.small}>An agro based app for farmers and persons</Text>
                        {
          this.state.ActivityLoader ? <ActivityIndicator color='#FFF' size='large' style={styles.Activity} />: null
        }
                    </View>

            <View style={{flex:2}}>
                    <TextInput
                    style={styles.input}
                    placeholder="Email Address"
                    returnKeyType="next"
                    keyboardType="email-address"
                    autoCapitalize="none"
                    autoCorrect={false}
                    onSubmitEditing = {() => this.passwordInput.focus()}
                    placeholderTextColor="rgba(255,255,255,.7)"
                    name="email"
                    onChangeText={(TextInput) => this.setState({userEmail: TextInput})}

                    />
                    <TextInput
                    style={styles.input}
                    placeholder="Password"
                    returnKeyType="go"
                    secureTextEntry
                    ref={(input) => this.passwordInput = input}
                    placeholderTextColor="rgba(255,255,255,.7)"
                    name="password"
                    onChangeText={(TextInput) => this.setState({password: TextInput})}
                    />

                    <TouchableOpacity style={styles.buttonContainer} onPress={ this.LoginUser }>
                        <Text style={styles.buttonText}>LOG IN</Text>
                    </TouchableOpacity>
            </View>

                    <View style={styles.bottomRow}>
                    <Text style={styles.signupText}> Don't have account ?
                    <Text style={styles.reg} onPress={() => this.props.navigation.navigate('RegisterScreen')}>REGISTER HERE</Text>
                    </Text>
                    </View>
                </View>
            </ImageBackground>
   </ScrollView>
</KeyboardAvoidingView>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
},
title: {
marginTop: 20,
alignItems: "center",
justifyContent:"center",
// height:'30%'
flex:1
},
big: {
marginTop: 20,
fontSize: 50,
color: "white",
alignItems:"center",
fontWeight:"bold",
},
small: {
marginTop: 4,
fontSize: 20,
color:"#FFF",
fontWeight:"bold",
opacity: .8
},
bottomRow: {
padding: 20,
justifyContent: "center",
paddingVertical: 20
},
signupText: {
fontSize: 21,
color:"#FFF",
fontWeight: "700",
alignItems: "center"
},
reg: {
color: "#FED81E",
alignItems: "center"
},
formContainer:{
padding: 20,
flex:1
},
input: {
height: 50,
backgroundColor: "green",
color: "#FFF",
paddingHorizontal: 10,
marginBottom: 10,
borderRadius: 7,
fontSize: 20,
paddingVertical: 10
},
buttonContainer: {
backgroundColor: "#FFF",
paddingVertical: 15,
borderRadius: 8
},
buttonText: {
textAlign: 'center',
color:"green",
fontWeight: '700',
fontSize: 27
},
Activity:{
position: 'absolute',
left: 0,
right: 0,
top: 150,
bottom: 0,
alignItems: 'center',
justifyContent: 'center',
zIndex: 999
},
});

如果你在android中运行上面的代码然后改变behavior={"height"}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何修复每当我在 Expo React-Native 中使用 KeyboardAwareView 或 React-native-keyboard-aware-scroll-view 时显示的白色键盘空间? 的相关文章

  • Android ToggleButton 始终检查

    如果切换按钮处于选中或取消选中状态 我想存储在 SharedPreferences 中 toggle setOnCheckedChangeListener new OnCheckedChangeListener public void on
  • Android:如何暂停和恢复可运行线程?

    我正在使用 postDelayed 可运行线程 当我按下按钮时 我需要暂停并恢复该线程 请任何人帮助我 这是我的主题 protected void animation music6 music4 postDelayed new Runnab
  • Android Camera.takePicture() 有时不返回?

    我正在编写一个Android 拍照应用程序 该代码在 onPreviewFrame byte data Cameracamera 中从预览中获取帧后进行一些处理 问题在于 android hardware Camera 的函数 takePi
  • 如何在 Android 应用程序中隐藏 Flutterwave API 密钥

    我正在构建一个 Android 应用程序 目前正在将 Flutterwave 集成到我的应用程序中以进行支付 建议我永远不要将 Flutterwave API 密钥放在我的应用程序上 那么我该如何隐藏这些键呢 我正在使用 Retrofit
  • 写入 Android UI Automator 输出控制台

    我正在 Android UI Automator 上编写一个小包装器 通常我们可以在控制台看到测试用例的状态 我可以访问它并添加我自己的消息吗 我努力了System out println 但这没有用 有什么办法可以做到这一点吗 您可以使用
  • 4 天后,应用仍未在 Google Play 搜索中编入索引

    我已经在 4 天前在 google play 上发布了我的第一个应用程序 语音到短信 但我仍然无法通过其名称或开发人员名称在搜索中找到我的应用程序 我只能通过包名称或真实应用程序名称 但不带空格 找到我的应用程序 VoiceToSMS 链接
  • Play 商店中的应用描述更新

    我想更新应用程序的描述以及 Play 商店上的屏幕截图 但应用程序保持相同 即相同的版本号 我不想发布新应用程序 因为应用程序中没有任何更改 这可能吗 谷歌也会要求更新应用程序吗 您可以更新描述 也可以更改屏幕截图 您的应用程序将保持不变
  • 更改语言 Flutter 的按钮

    我正在 Flutter 中构建一个应用程序 到目前为止 我正在使用 JSON 国际化 其中应用程序的语言基于用户手机中默认的语言 它工作得很好 但我想给用户有机会在不更改手机系统语言设置的情况下更改语言 只需单击按钮 然后应用程序即可更改语
  • Android L,使用 joda.time 库的异常

    该应用程序适用于所有设备 包括 nexus 5 和 nexus 7 在 Android L 预览版上运行相同的应用程序时 应用程序崩溃了 我一直在调试 并且调用 DateTime 构造函数发现了异常 public static String
  • 如何使用 TypeScript、Jest 和 Enzyme 测试 React 中的按钮点击

    我正在使用 TypeScript 构建一个 React Native 应用程序 我正在使用 Jest 和 Enzyme 进行组件测试 我也在使用 React 导航 我正在努力编写单击按钮的单元测试 这是组件的代码 只是渲染函数 render
  • 尝试注册 RCTBridgeModule 类 RCTFileReaderModule

    尝试为名称 FileReaderModule 注册 RCTBridgeModule 类 RCTFileReaderModule 但该名称已由类 FileReaderModule 注册 尝试使用命令react native run ios在i
  • 在 Android 中加密/解密字符串的简单方法

    我的问题是如何加密String String AndroidId Override public void onCreate Bundle savedInstanceState super onCreate savedInstanceSta
  • 模拟器无法加载

    我正在使用 hello android 教程并通过 eclipse 创建 avd 启动模拟器时不使用图像 它只是显示一个黑色的后屏 中间有 ANDROID 字样 并且在 ANDROID 字样的末尾有一个闪烁的光标 我已按照 T 的步骤安装
  • Android - 状态栏阻止全屏

    我的应用程序启动时可以全屏正确运行 然而 在最小化然后返回应用程序后 状态栏会弹出 并将我的视图向下推一点 如何防止状态栏移动我的视图 这是我的布局
  • 如何将 JSON 数据从 Android 发送到 php url?

    我想将登录信息从我的应用程序发送到 php url 因为这我的应用程序将崩溃 任何人都可以帮助我解决这个问题 这是我的服务器登录方法 我想将数据发送到此登录方法 Method public method login Parameters 3
  • Expresso 的 Android 测试首选项片段

    我在通过 Expresso 测试我的代码时遇到问题 我写了这段代码 public class SettingsActivity extends Activity Override protected void onCreate Bundle
  • 了解应用程序在后台时何时收到 Firebase 消息

    我知道这个标题有同样的问题 但不幸的是它没有得到正确的回答 它被接受了 here https stackoverflow com questions 37711082 how to handle notification when app
  • 使 Recyclerview 固定高度并可滚动

    已解决以下检查答案 所以我试图为我的 Android 应用程序创建评论功能 我想在 recyclerview 中显示评论 然后在 recyclerview 下方有一个按钮和文本视图来添加评论 我想让 recyclerview 具有一定的高度
  • XML 配置中的 screenName 不起作用

    我刚刚在我的应用程序中添加了对 Google Analytics 分析 的支持 但我无法
  • 动态更改按钮上的图像视图

    在我的应用程序中 我有按钮和ImageView 当我按下按钮时我想改变ImageView 我的可绘制文件夹中有 5 张图像 按下按钮时 ImageView 根据按钮单击一张一张地更改图像 我想要它的解决方案 感谢任何可以提供帮助的人 维护一

随机推荐