Hard
### Si je dois conditionner mon code en fonction d'iOS ou d'Android, comment dois-je procéder ?
Code A:
* fichier index.ios.js
import React from "react";
class MyIosComponent extends React.Component {
render () {
return (<Element>I’m in iOS</Element>);
}
}
* fichier index.android.js
import React from "react";
class MyAndroidComponent extends React.Component {
render () {
return (<Element>I’m in Android</Element>);
}
}
Code B:
import React from "react";
import {Platform} from "react-native";
class MyComponent extends React.Component {
render () {
return device.platform === "iOS"
? (<Element>I’m in iOS</Element>)
: (<Element>I’m in Android</Element>)
}
}
Code C:
import React from "react";
import {Platform} from "react-native";
class MyComponent extends React.Component {
render () {
return Platform.select({
ios: () => (<Element>I’m in iOS</Element>),
android: () => (<Element>I’m in Android</Element>)
})
}
}
Author: Victor SabatierStatus: PublishedQuestion passed 417 times
Edit
2
Community EvaluationsNo one has reviewed this question yet, be the first!
5
Write a React Native animation that spins an image.1
How to set the background color of a View in React Native2
How to use StyleSheet in React Native1
What is the output of the following code?
const App = () => {
const [count, setCount] = useState(0);
return ({
<Text>
The count is {count}
</Text>
<Button onPress={() => setCount(count + 1)}>
Increase
</Button>
});
};
export default App;
1
I can launch the debugger in Chrome from my app, I run `react-native log-ios` from my command line1
Which of the following snippets are valid JSX?0
Which of the following code snippets will print 'Hello World' to the console?