英文:
React-Native styles not getting appplied
问题
以下是您提供的代码的翻译部分:
// 在两个屏幕中未应用React-Native样式,已保存更改,但应用到一个屏幕后,另一个屏幕失去样式。以下是代码:
import { render } from 'react-dom';
import { NavigationContainer } from '@react-navigation/native';
import { TextInput } from 'react-native-gesture-handler';
const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
styles = StyleSheet.create({
Container: {
flex: 1,
width: '100%',
width: width - 20,
height: height - 10,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
ViewContainer: {
width: width - 40,
flex: 1,
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
input: {
borderBottomColor: '#F5FCFF',
backgroundColor: '#FFFFFF',
borderRadius: 30,
borderBottomWidth: 1,
paddingLeft: 8,
width: 250,
height: 45,
marginBottom: 8,
marginTop: 20,
flexDirection: 'row',
alignItems: 'center',
marginLeft: 40
},
Button: {
width: "80px",
height: "30px",
margin: 100,
justifyContent: 'flex-end',
alignItems: "flex-end",
},
buttonContainer: {
height: 65,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginBottom: 20,
width: 250,
borderRadius: 30,
marginLeft: 70
},
Container: {
flex: 1,
justifyContent: "flex-end",
alignItems: "flex-end",
},
})
// 另一个屏幕的代码:
import AsyncStorage from '@react-native-async-storage/async-storage';
import { render } from 'react-dom';
import { NavigationContainer } from '@react-navigation/native';
import { TextInput } from 'react-native-gesture-handler';
import { getPermissionsAsync } from 'expo-location';
const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
styles = StyleSheet.create({
Container: {
flex: 1,
width: width - 20,
height: height - 30,
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
input: {
marginTop: height / 4,
margin: 20,
borderBottomColor: '#F5FCFF',
backgroundColor: '#FFFFFF',
borderRadius: 30,
borderBottomWidth: 1,
width: 250,
height: 45,
marginBottom: 20,
flexDirection: 'row',
alignItems: 'center',
marginLeft: 70
},
Button: {
height: 45,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginBottom: 20,
width: 250,
borderRadius: 60,
borderBottomWidth: 1,
marginTop: 90,
marginLeft: 70
},
Button2: {
flex: 1,
height: 20,
borderRadius: 60,
borderBottomWidth: 1,
width: 30,
color: '#f0f8ff',
alignSelf: 'flex-end',
borderStyle: 'dashed'
}
})
// 使用堆栈导航,可能是问题所在,以下是代码:
function Tabnav() {
return (
<Tab.Navigator
screenOptions={{
tabBarActiveTintColor: '#101010',
TabBarLabelStyle: {
fontSize: 15,
},
TabBarStyle: {
backgroundColor: '#ffd700',
}
}}
>
<Tab.Screen name="Homescreen" component={Home}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Ionicons name="ios-home" color={color} size={size} />
)
}} />
<Tab.Screen name="Perfil" component={userProfile}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Ionicons name="ios-person" size={size} color={color} />
)
}} />
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer initialRouteName="Signin">
<Stack.Navigator>
<Stack.Screen name="Signin" component={Signin} />
<Stack.Screen name="Register" component={Register} />
<Stack.Screen name="Forgotpass" component={Forgotpass} />
<Stack.Screen name="Reset" component={Reset} />
<Stack.Screen name="Home" component={Tabnav} options={{ headerLeft: () => null, gestureEnabled: false, }} />
<Stack.Screen name="Dermatologistas" component={Dermatologistas} />
<Stack.Screen name="Hospitais" component={Hospitais} />
<Stack.Screen name="Cardiologista" component={Cardiologista} />
<Stack.Screen name="Pneumologista" component={Pneumologista} />
<Stack.Screen name="Odontologo" component={Odontologo} />
<Stack.Screen name="Oftalmologista" component={Oftalmologista} />
<Stack.Screen name="UserProfile" component={userProfile} />
<Stack.Screen name="Profile" component={Profile} />
<Stack.Screen name="Edit" component={Edit} />
</Stack.Navigator>
</NavigationContainer>
);
}
希望这有助于您的问题。如果需要进一步的帮助,请告诉我。
英文:
React-Native styles are not getting applied in two screens, I already saved the changes but when it gets applie to one screen, the other one loses it's style. Here is the code :
import { render } from 'react-dom';
import {NavigationContainer} from '@react-navigation/native'
import { TextInput } from 'react-native-gesture-handler';
const width = Dimensions.get('window').width
const heigth = Dimensions.get('window').height
styles = StyleSheet.create({
Container:{
flex:1,
width: '100%',
width: width -20,
height:heigth - 10,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
ViewContainer:{
width: width -40,
flex:1,
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
input:{
borderBottomColor: '#F5FCFF',
backgroundColor: '#FFFFFF',
borderRadius:30,
borderBottomWidth: 1,
paddingLeft: 8,
width:250,
height:45,
marginBottom:8,
marginTop:20,
flexDirection: 'row',
alignItems:'center',
marginLeft:40
},
Button:{
width:"80px",
height:"30px",
margin:100,
justifyContent:'flex-end',
alignItems: "flex-end",
},
buttonContainer: {
height:65,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginBottom:20,
width:250,
borderRadius:30,
marginLeft:70
},
Container:{
flex:1,
justifyContent:"flex-end",
alignItems: "flex-end",
},
})
and the other one here:
import AsyncStorage from '@react-native-async-storage/async-storage';
import { render } from 'react-dom';
import {NavigationContainer} from '@react-navigation/native'
import { TextInput } from 'react-native-gesture-handler';
import { getPermissionsAsync } from 'expo-location';
const width = Dimensions.get('window').width
const heigth = Dimensions.get('window').height
styles = StyleSheet.create({
Container:{
flex:1,
width: width -20,
height:heigth-30,
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
input:{
marginTop: heigth/4,
margin: 20,
borderBottomColor: '#F5FCFF',
backgroundColor: '#FFFFFF',
borderRadius:30,
borderBottomWidth: 1,
width:250,
height:45,
marginBottom:20,
flexDirection: 'row',
alignItems:'center',
marginLeft:70
},
Button:{
height:45,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginBottom:20,
width:250,
borderRadius:60,
borderBottomWidth: 1,
marginTop:90,
marginLeft:70
},
Button2:{
flex:1,
height:20,
borderRadius:60,
borderBottomWidth: 1,
width:30,
color:'#f0f8ff',
alignSelf:'flex-end',
borderStyle: 'dashed'
}
})
I'm using stack navigation and think that it migth be the problem, here is the code:
function Tabnav() {
return(
<Tab.Navigator
screenOptions={{
tabBarActiveTintColor: '#101010',
TabBarLabelStyle: {
fontSize: 15,
},
TabBarStyle: {
backgroundColor: '#ffd700',
}
}}
>
<Tab.Screen name="Homescreen" component={Home}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Ionicons name="ios-home" color={color} size={size} />
)
}}/>
<Tab.Screen name="Perfil" component={userProfile}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Ionicons name="ios-person" size={size} color={color} />
)
}}/>
</Tab.Navigator>
);
}
export default function App(){
return (
<NavigationContainer initialRouteName="Signin">
<Stack.Navigator>
<Stack.Screen name="Signin" component={Signin} />
<Stack.Screen name="Register" component={Register}/>
<Stack.Screen name="Forgotpass" component={Forgotpass}/>
<Stack.Screen name="Reset" component={Reset}/>
<Stack.Screen name="Home" component={Tabnav} options={{headerLeft:()=>null, gestureEnabled: false,}}/>
<Stack.Screen name="Dermatologistas" component={Dermatologistas}/>
<Stack.Screen name="Hospitais" component={Hospitais}/>
<Stack.Screen name="Cardiologista" component={Cardiologista}/>
<Stack.Screen name="Pneumologista" component={Pneumologista}/>
<Stack.Screen name="Odontologo" component={Odontologo}/>
<Stack.Screen name="Oftalmologista" component={Oftalmologista}/>
<Stack.Screen name="UserProfile" component={userProfile}/>
<Stack.Screen name="Profile" component={Profile}/>
<Stack.Screen name="Edit" component={Edit}/>
</Stack.Navigator>
</NavigationContainer>
);
}
答案1
得分: 3
需要从react-native导入StyleSheet。
import { StyleSheet, View, Text } from "react-native";
英文:
Need to import StyleSheet from react-native
import {StyleSheet, View, Text} from "react-native";
答案2
得分: 1
You have forgotten the const keyword.
const styles = StyleSheet.create({
You have forgotten to import StyleSheet, so this may be another problem.
If the StyleSheet is declared in a separate file, you must export it like this:
export default styles or export {styles}
To use styles in other files, if you do export default styles
like this, then import like this:
import styles from "../your/directory/to/styles/"
If you export like this:
export {styles}
Then import like this:
import {styles} from "../your/directory/to/styles/"
英文:
you have for got the const keyword.
const styles = StyleSheet.create({
you have forgot to import StyleSheet
so this may be another Problem.
if the StyleSheet is declare in separate file you must have to export it like this
export default styles or export {styles}
to use styles in the other files . if you do export default styles
like this then import like this
import styles from "../your/directroy/to/styles/"
if you export like this
export {styles}
then import like this
import {styles} from "../your/directroy/to/styles/"
答案3
得分: 0
"just needed to define a const in the stylesheet :)\n\nstyles = StyleSheet.create({})"
英文:
just needed to define a const in the stylesheet
styles = StyleSheet.create({})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论