I am using Platform.OS to check ios and android. It is working fine, But suddenly it returns me 0 instead of 'ios' or 'android'. After some RND I found that when the app is loading the first time, it returns me 'android' but when I switch the screen and check Platform.OS then it returns me 0 value. I am wondered why it is happening.
I am sharing the console result.
when the app is reloading the first time.
LOG Platform.OS
LOG android
after that navigate to the other screen and then check Platform OS.
LOG Platform.OS
LOG 0
I am sharing the code snippet to check Platform
import { Platform } from 'react-native';
componentDidMount() {
console.log('Platform.OS');
console.log(Platform.OS);
}
It looks like you used Platform.OS "=" instead of "==" someplace within the code. Example :
wrong way:
(Platform.OS ='android')?console.log("this the wrong way):console.log('Oops')
right way
(Platform.OS=='android')?console.log("Youpi it works):console.log('in your dream, this gonna happen again')
The same thing happened to me.
I noted that in one place I have checked platform condition using a single equal operator by mistake like
paddingTop: (Platform.OS = 'android'? 16 : 4)
and then whenever I checked the platform, I always got 16.
So make sure if anywhere you have check condition, like Platform.OS = 'android' replace it with Platform.OS == 'android'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With