I’m building my app with react native. I want the same code and UI for all three platforms. Web, Android, and, IOS. This is my app.json file
{
"expo": {
"name": "game-app",
"slug": "game-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"backgroundColor": "#14206b",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#14206b"
},
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#14206b"
}
},
"web": {
"favicon": "./assets/favicon.png",
"backgroundColor": "#14206b"
}
}
}
What I’m trying to do is change the background color in my web app for the whole application setting. I have changed the app.json like the above code. But it’s still not working. It works on my android well.
Here’s the JS codes:
App.js
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import StartGameScreen from './screens/StartGameScreen';
export default function App() {
return (
<StartGameScreen/>
);
}
const styles = StyleSheet.create({});
StartGameScreen.js
import {View, TextInput} from 'react-native'
import PrimaryButton from '../components/PrimaryButton';
import { StyleSheet } from 'react-native';
import { Platform } from 'react-native';
function StartGameScreen() {
return (
<View style={styles.inputContainer}>
<TextInput/>
<PrimaryButton>Reset</PrimaryButton>
<PrimaryButton>Confirm</PrimaryButton>
</View>
)
}
export default StartGameScreen;
const styles = StyleSheet.create({
inputContainer: {
padding: 16,
height: Platform.OS === 'web' ? 100 : 100,
marginTop: 100,
margin: 50,
backgroundColor: '#72063c',
alignItems: 'center',
width: Platform.OS === 'web' ? '95vw' : '95vw', // Adjust width for web
}}
)
2
Answers
As it is being changed in the app.json, reloading might work. It works for me as well. Also make sure the inputContainer cover up the entire screen, as it is having a different color. As you are using 95vw, I think you can see the different background color.
After spending a lot of time reading react-native documentation, I realized that when you apply a background color in the
app.json
, it doesn’t apply in IOS as intended.You can achieve this by using
expo-system-ui
as recommended by the expo teamWhat documentation says on backgroundColor property