Javascript 主题未应用于本机应用程序
因此,我一直在尝试将一些样式应用于我的页面,我注意到文本输入元素的样式不受theme.js文件的任何影响。我已经导入了所有必要的文件,解决这个问题的唯一方法是应用我不喜欢使用的内联样式。我的应用程序正在运行,没有任何错误,所以我不知道去哪里看。在使用它之后,我认为问题在于textInput.js没有应用到任何页面,仍然没有找到解决方案 App.jsJavascript 主题未应用于本机应用程序,javascript,css,react-native,Javascript,Css,React Native,因此,我一直在尝试将一些样式应用于我的页面,我注意到文本输入元素的样式不受theme.js文件的任何影响。我已经导入了所有必要的文件,解决这个问题的唯一方法是应用我不喜欢使用的内联样式。我的应用程序正在运行,没有任何错误,所以我不知道去哪里看。在使用它之后,我认为问题在于textInput.js没有应用到任何页面,仍然没有找到解决方案 App.js import React from 'react'; import { createAppContainer, createSwitchNaviga
import React from 'react';
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import AccountScreen from './src/screens/AccountScreen';
import SigninScreen from './src/screens/SigninScreen';
import SignupScreen from './src/screens/SignupScreen';
import GroupListScreen from './src/screens/GroupListScreen';
import GameListScreen from './src/screens/GameListScreen'
import FriendListScreen from './src/screens/FriendListScreen'
import StartScreen from './src/screens/StartScreen';
import {theme} from './src/core/theme'
const switchNavigator = createSwitchNavigator({
Start:StartScreen,
loginFlow: createStackNavigator({
Signup: SignupScreen,
Signin: SigninScreen,
}),
mainFlow: createBottomTabNavigator({
GameList:GameListScreen,
GroupList: GroupListScreen,
FriendList:FriendListScreen,
Account: AccountScreen,
}),
});
export default createAppContainer(switchNavigator);
注册屏幕
import React, { useState } from 'react'
import { View, StyleSheet, TouchableOpacity } from 'react-native'
import { Text } from 'react-native-paper'
import Background from '../components/Background'
import Logo from '../components/Logo'
import Header from '../components/Header'
import Button from '../components/Button'
import TextInput from '../components/TextInput'
import BackButton from '../components/BackButton'
import { theme } from '../core/theme'
import { emailValidator } from '../helpers/emailValidator'
import { passwordValidator } from '../helpers/passwordValidator'
import { nameValidator } from '../helpers/nameValidator'
const SignupScreen =({ navigation }) => {
const [name, setName] = useState({ value: '', error: '' })
const [email, setEmail] = useState({ value: '', error: '' })
const [password, setPassword] = useState({ value: '', error: '' })
const onSignUpPressed = () => {
const nameError = nameValidator(name.value)
const emailError = emailValidator(email.value)
const passwordError = passwordValidator(password.value)
if (emailError || passwordError || nameError) {
setName({ ...name, error: nameError })
setEmail({ ...email, error: emailError })
setPassword({ ...password, error: passwordError })
return
}
}
return (
<Background>
<BackButton goBack={navigation.goBack} />
<Logo />
<Header>Create Account</Header>
<TextInput
label="Username"
returnKeyType="next"
value={name.value}
onChangeText={(text) => setName({ value: text, error: '' })}
error={!!name.error}
errorText={name.error}
/>
<TextInput
label="Email"
returnKeyType="next"
value={email.value}
onChangeText={(text) => setEmail({ value: text, error: '' })}
error={!!email.error}
errorText={email.error}
autoCapitalize="none"
autoCompleteType="email"
textContentType="emailAddress"
keyboardType="email-address"
/>
<TextInput
label="Password"
returnKeyType="done"
value={password.value}
onChangeText={(text) => setPassword({ value: text, error: '' })}
error={!!password.error}
errorText={password.error}
secureTextEntry
/>
<Button
mode="contained"
onPress={onSignUpPressed}
style={{ marginTop: 24 }}
>
Sign Up
</Button>
<View style={styles.row}>
<Text>Already have an account? </Text>
<TouchableOpacity onPress={() => navigation.replace('Signin')}>
<Text style={styles.link}>Login</Text>
</TouchableOpacity>
</View>
</Background>
)
}
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
marginTop: 4,
},
link: {
fontWeight: 'bold',
color: theme.colors.primary,
},
})
export default SignupScreen;
组件文件夹中的TextInput.js
import React from 'react'
import { View, StyleSheet, Text } from 'react-native'
import { TextInput as Input } from 'react-native-paper'
import { theme } from '../core/theme'
export default function TextInput({ errorText, description, ...props }) {
return (
<View style={styles.container}>
<Input
style={styles.input}
selectionColor={theme.colors.primary}
underlineColor="transparent"
mode="outlined"
{...props}
/>
{description && !errorText ? (
<Text style={styles.description}>{description}</Text>
) : null}
{errorText ? <Text style={styles.error}>{errorText}</Text> : null}
</View>
)
}
const styles = StyleSheet.create({
container: {
width: '100%',
marginVertical: 12,
},
input: {
backgroundColor: theme.colors.surface,
borderColor: theme.colors.text,
},
description: {
fontSize: 13,
color: theme.colors.text,
paddingTop: 8,
},
error: {
fontSize: 13,
color: theme.colors.error,
paddingTop: 8,
},
})
从“React”导入React
从“react native”导入{视图、样式表、文本}
从“react native paper”导入{TextInput as Input}
从“../core/theme”导入{theme}
导出默认函数TextInput({errorText,description,…props}){
返回(
{说明&&!错误文本(
{说明}
):null}
{errorText?{errorText}:null}
)
}
const styles=StyleSheet.create({
容器:{
宽度:“100%”,
玛吉:12,
},
输入:{
背景色:theme.colors.surface,
borderColor:theme.colors.text,
},
说明:{
尺寸:13,
颜色:theme.colors.text,
paddingTop:8,
},
错误:{
尺寸:13,
颜色:theme.colors.error,
paddingTop:8,
},
})
import React from 'react'
import { View, StyleSheet, Text } from 'react-native'
import { TextInput as Input } from 'react-native-paper'
import { theme } from '../core/theme'
export default function TextInput({ errorText, description, ...props }) {
return (
<View style={styles.container}>
<Input
style={styles.input}
selectionColor={theme.colors.primary}
underlineColor="transparent"
mode="outlined"
{...props}
/>
{description && !errorText ? (
<Text style={styles.description}>{description}</Text>
) : null}
{errorText ? <Text style={styles.error}>{errorText}</Text> : null}
</View>
)
}
const styles = StyleSheet.create({
container: {
width: '100%',
marginVertical: 12,
},
input: {
backgroundColor: theme.colors.surface,
borderColor: theme.colors.text,
},
description: {
fontSize: 13,
color: theme.colors.text,
paddingTop: 8,
},
error: {
fontSize: 13,
color: theme.colors.error,
paddingTop: 8,
},
})