我的反应本机应用程序中的一个屏幕有一个简单的用户注册页面 UI。我使用命令
eas build -p android --profile preview
生成了一个 android apk。生成的 apk 在模拟器上运行时没有问题:Pixel 5(这是 apk,而不是通过 Expo Go 运行的应用程序),但是当我将其安装在设备上时 - OnePlus 5t - 它有一些不完整显示的字符串。
展示每个的屏幕截图:-
1。模拟器 Pixel 5
2。设备 OnePlus5t
查看按钮下方的标签和文字
屏幕的代码片段。
1。注册屏幕.tsx
import { Text } from '@components';
import { useAlertToast } from '@hooks';
import { useNavigation } from '@react-navigation/native';
import { setAuthState, useRegisterMutation } from '@store';
import { Button, Center, FormControl, Input, Link, Stack, WarningOutlineIcon } from 'native-base';
import React, { useCallback, useEffect, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { KeyboardAvoidingView, StyleSheet } from 'react-native';
import { useDispatch } from 'react-redux';
import { StackNavProps } from 'StackNavigation';
import { saveEntryAsJson } from '../../utils/AsyncStorage';
import { Screens } from '../../utils/constants';
type RegisterationForm = {
name: string;
email: string;
password: string;
};
export const Register = () => {
const {
control,
handleSubmit,
formState: { errors },
} = useForm<RegisterationForm, any>({
defaultValues: {
name: "",
email: "",
password: "",
},
});
const { navigate } = useNavigation<StackNavProps>();
const [register, registerResult] = useRegisterMutation();
const { showErrorToast } = useAlertToast();
const dispath = useDispatch();
useEffect(() => {
if (registerResult.isSuccess) {
saveEntryAsJson("userData", registerResult.data);
dispath(setAuthState(registerResult.data));
navigate(Screens.VERIFY_OTP);
} else if (registerResult.isError) {
//@ts-ignore
showErrorToast(registerResult.error.data.message);
}
}, [registerResult.isSuccess]);
const onSubmit = useCallback(async (data: RegisterationForm) => {
await register({
...data,
}).unwrap();
}, []);
return (
<KeyboardAvoidingView style={styles.container}>
<Center style={styles.innerContainer}>
<FormControl isInvalid={!!errors.name} marginY={3}>
<Stack mx="4">
<FormControl.Label>
<Text style={styles.inputLabel}>Username </Text>
</FormControl.Label>
<Controller
control={control}
rules={{
required: true,
}}
render={({ field: { onChange, onBlur, value } }) => (
<Input
onBlur={onBlur}
onChangeText={onChange}
value={value}
placeholder="Enter user name"
/>
)}
name="name"
/>
{errors.name?.type === "required" && (
<FormControl.ErrorMessage
leftIcon={<WarningOutlineIcon size="xs" />}
>
User name is required
</FormControl.ErrorMessage>
)}
</Stack>
</FormControl>
<FormControl isInvalid={!!errors.email} marginY={3}>
<Stack mx="4">
<FormControl.Label>
<Text style={styles.inputLabel}>Email </Text>
</FormControl.Label>
<Controller
control={control}
rules={{
required: true,
// pattern: RegExp("/^w+([.-]?w+)*@w+([.-]?w+)*(.ww+)+$/"),
}}
render={({ field: { onChange, onBlur, value } }) => (
<Input
onBlur={onBlur}
onChangeText={onChange}
value={value}
placeholder="Enter email address"
keyboardType="email-address"
/>
)}
name="email"
/>
{errors.email?.type === "pattern" && (
<FormControl.ErrorMessage
leftIcon={<WarningOutlineIcon size="xs" />}
>
Invalid email address
</FormControl.ErrorMessage>
)}
{errors.email?.type === "required" && (
<FormControl.ErrorMessage
leftIcon={<WarningOutlineIcon size="xs" />}
>
Email address required
</FormControl.ErrorMessage>
)}
</Stack>
</FormControl>
<FormControl isInvalid={!!errors.password} marginY={3}>
<Stack mx="4">
<FormControl.Label>
<Text style={styles.inputLabel}>Password</Text>
</FormControl.Label>
<Controller
control={control}
rules={{
required: true,
minLength: 8,
}}
render={({ field: { onChange, onBlur, value } }) => (
<Input
onBlur={onBlur}
onChangeText={onChange}
value={value}
placeholder="Enter password"
type="password"
/>
)}
name="password"
/>
{errors.password?.type === "minLength" && (
<FormControl.ErrorMessage
leftIcon={<WarningOutlineIcon size="xs" />}
>
Atleast 8 characters are required.
</FormControl.ErrorMessage>
)}
{errors.password?.type === "required" && (
<FormControl.ErrorMessage
leftIcon={<WarningOutlineIcon size="xs" />}
>
Password required.
</FormControl.ErrorMessage>
)}
</Stack>
</FormControl>
<Button
colorScheme={"orange"}
style={styles.registerButton}
onPress={handleSubmit(onSubmit)}
>
{"Register "}
</Button>
<Link style={styles.otherLink} onPress={() => navigate(Screens.LOGIN)}>
<Text>Already registered?. Login here.</Text>
</Link>
</Center>
</KeyboardAvoidingView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
inputLabel: {
fontWeight: "700",
color: "black",
},
innerContainer: {
flex: 1,
paddingHorizontal: 5,
},
registerButton: {
borderRadius: 5,
padding: 5,
marginTop: 20,
},
otherLink: {
marginTop: 10,
},
});
2。文本组件
import { ITextProps, Text as NativeText } from 'native-base';
export const Text = ({ children, ...rest }: ITextProps) => {
return (
<NativeText
_light={{ color: "black" }}
_dark={{ color: "white" }}
{...rest}
>
{children}
</NativeText>
);
};
我尝试在字符串后面添加额外的空格和 {" "},但没有成功。我注意到在运行“Expo Go”时模拟器上有时会出现此问题,并且通过在字符串后添加额外的空格来解决此问题,但在生成 apk 时似乎不起作用。
我也遇到过这个问题,这是我为解决 xa 所做的事情
<Text >Hellor word {' '} </Text>
<Text > {myTexT + " "} </Text>