This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Add standard: what differences between iOS and android should I be aware of #146
Open
pleportz
wants to merge
5
commits into
master
Choose a base branch
from
add-differences-android-ios
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d58a27d
Add standard: what differences between iOS and android should I be aw…
pleportz b6f43cb
Format improvements
pleportz e77e45b
Add check for the native code modification case
pleportz b8e032a
Add checks part
pleportz edac22c
Improve Checks part
pleportz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
react-native/debugging/differences-between-ios-and-android.s.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# [Standard] What differences between iOS and android should I be aware of as a react-native developer? | ||
## ... and when should I double check my feature on both platforms? | ||
|
||
*react-native is awesome because it lets you build both iOS and android apps with the same javascript codebase...* | ||
|
||
While coding I usually use the iOS simulator only. Most of the time, if the feature works on iOS then it works on android automatically. Of course there are a few exceptions: in this article you will find a non comprehensive list of these exceptions. | ||
|
||
## Owner: [Pierre-Louis Le Portz](https://github.com/pleportz) | ||
|
||
## Checks | ||
|
||
If I am in one of the cases below, I made sure to check my feature on both ios and android before deploying to the validation platform. | ||
|
||
## I modified the native code | ||
|
||
*Check: there is a commit change in either the `android/` or the `ios/. directory* | ||
|
||
- I added/updated a **font** | ||
|
||
- Why: You might have forgotten to update the font for one of the two OSs. | ||
- References: See [How to add/update icons with an icomoon font](https://github.com/bamlab/dev-standards/blob/master/react-native/features/icomoon.mo.md) and [How to add a new font to a react-native app](https://medium.com/react-native-training/react-native-custom-fonts-ccc9aacf9e5e) | ||
|
||
|
||
- I installed a **native library** | ||
|
||
- Why: | ||
|
||
- The installation process depends on the platform | ||
- For many reasons, the building phase might go wrong with one of the OSs. For instance there might be code signing issues with iOS | ||
- Once installed, the library might behave differently on iOS and android | ||
|
||
- References: See [How to add a native module](https://github.com/bamlab/dev-standards/blob/master/react-native/setup/add-native-module.mo.md) | ||
|
||
## I added a fixed height property to a component | ||
|
||
- Why: Unlike iOS, android sets the default behaviour to the react-native `<View />` component to `overflow: hidden`. Using a fixed height often ends up with cut texts or cut images on android. | ||
|
||
## I added shadows to a component | ||
|
||
- Works on iOS / does not on android: | ||
|
||
```javascript | ||
<View style={styles.container}><Text>Hello</Text></View> | ||
|
||
const styles = { | ||
container: { | ||
shadowColor: 'grey', | ||
shadowRadius: 10, | ||
shadowOpacity: 0.2, | ||
shadowOffset: { height: 1, width: 1 }, | ||
elevation: 3, | ||
}, | ||
} | ||
``` | ||
|
||
- Works on both platforms: | ||
|
||
```javascript | ||
<View style={styles.container}><Text>Hello</Text></View> | ||
|
||
const styles = { | ||
container: { | ||
shadowColor: 'grey', | ||
shadowRadius: 10, | ||
shadowOpacity: 0.2, | ||
shadowOffset: { height: 1, width: 1 }, | ||
elevation: 3, | ||
backgroundColor: 'white', // <-- backgroundColor is mandatory for android | ||
}, | ||
} | ||
``` | ||
|
||
## I used react-native's `<TextInput />` component | ||
|
||
- Why: <TextInput /> does not render identically on android and iOS: | ||
|
||
- With android you might need to specify the `underlineColorAndroid` prop (can be set to `"transparent"` for example) | ||
- The vertical alignment of the input text is not the same. This can be solved by using a marginTop that depends on the platform: `marginTop: Platform.OS === 'ios ? ...'` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plutot mettre un padding: 0 sur le TextInput, sans distinction de plateforme |
||
|
||
## I mistakenly added text direcly as a `<View />`'s child | ||
|
||
- Why: `<View>Hello</View>` does not crash iOS but crashes on android with the following error `Cannot add a child that doesn't have a YogaNode to a parent without a measure function! (Trying to add a 'ReactVirtualTextShadowNode' to a 'NativeViewWrapper')` | ||
|
||
- Typical example - This is extremely dangerous on android: | ||
|
||
```javascript | ||
<View>{this.props.myText && <Text>this.props.myText</Text>}</View> | ||
``` | ||
|
||
If this.props.myText is equal to `''` then you end up with `<View>''</View>` and the app **crashes** on android. One way to do this correctly is: | ||
|
||
|
||
```javascript | ||
<View>{!!this.props.myText && <Text>this.props.myText</Text>}</View> | ||
``` | ||
|
||
## I used a javascript function that is not implemented the same way in react-native's javascript interpreters for android and iOS | ||
|
||
- Why: As of July 2018, react-native's javascript interpreter for android is a little bit late compared to iOS's. There are a few methods that just won't work with android: | ||
|
||
- `Number.prototype.toLocaleString()` | ||
- `String.prototype.normalize()` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
et des margin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ajouter un exemple avec screenshot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
premier step :
==> ne sont que pour ios
c'est elevation + backgroundcolor sur au moins un des composants qui contient le composant en question+ margin qui fait le travail