来自 TextInput 和 launch_screen 文件的相对布局错误

问题描述 投票:0回答:2

调试器给我的错误消息:

这将是向我抛出错误的组件。具体来说就是 TextInput。我尝试将其从组件中删除,错误消失了。

import { Formik } from "formik";
import { Button, TextInput, View } from 'react-native';
import { FormValues } from "./types";
import Box from "../../../../components/Box";

const Form = (): JSX.Element => {

    const initialValues: FormValues = {
        first_name: "",
        last_name: "",
        email: "",
        password: "",
        github_profile: "",
        linkedin_profile: ""
    }

    const onSubmit = () => {
        // handle submit
    }



    return (
        <Box style={{flex: 1, backgroundColor: 'black'}}>
            <Formik
            initialValues={initialValues}
            onSubmit={onSubmit}
        >
            {({ handleChange, handleBlur, handleSubmit, values }) => (
            <View>
                <TextInput
                onChangeText={handleChange('email')}
                onBlur={handleBlur('email')}
                value={values.email}
                />
                <Button onPress={() => handleSubmit()} title="Submit" />
            </View>
            )}
        </Formik>
        </Box>
        
    )
}

export default Form;

这将是我的 launch_screen 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/launch_screen" android:scaleType="centerCrop" />
</RelativeLayout>
android react-native android-relativelayout
2个回答
0
投票

你的 React Native 版本是什么?

你可以补充吗

import React from 'react';

你的依赖

编辑

这将是我的 launch_screen 文件:

从我的角度来看这没有任何意义😅。您不需要编写 XML。如果您想编写特定平台代码,可以找到相关指南 https://reactnative.dev/docs/platform-specific-code


0
投票

我也遇到了这个错误。就我而言,发生这种情况是因为我指向 styles.xml 中的 XML 文件。

styles.xml 文件:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- Customize your theme here. -->

    <!-- This line was creating the issue. So, I comment it. -->
    <!-- <item name="android:editTextBackground">@layout/launch_screen</item> -->
    
    <item name="android:windowBackground">@drawable/coldscreen</item>

    <item name="android:statusBarColor">
        @android:color/transparent
    </item>

</style>

评论后,我从 android studio 中清理了该项目,从我的移动设备中删除了该应用程序,然后再次在 Visual Code 中运行该项目。

launch_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/screen"
    android:scaleType="centerCrop"
    android:contentDescription="@string/todo" />
</RelativeLayout>

我的注册屏幕,当我使用 TextInput 时发生错误。我向你展示我的返回函数。评论该行后,我的应用程序运行良好。我希望这对你有帮助。

注册.tsx

<View style={styles.mainContainer}>
  <Text style={styles.Heading}>SignUp</Text>

  <View>
    <TextInput
        value='sadas' 
        placeholder='Enter email...'
        placeholderTextColor={'lightgray'}
        style={{backgroundColor: 'red', borderRadius: 10, borderWidth: 1}}
    />
  </View>

</View>
© www.soinside.com 2019 - 2024. All rights reserved.