-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PlatformColor API Added api documentation for the PlatformColor API function. * Incorrect quotation marks typo fix * removed platformcolor from versioned docs, moved it out of hooks * Update en.json * Added DynamicColorIOS section to colors.md * Updates to colors.md and platformcolor.md * Update colors.md example for dynamiccolorios added to it's section. * simplifier example for dynamiccolorios * simplified the dynamiccolorios jsx code example Co-authored-by: Kiki Saintonge <[email protected]>
- Loading branch information
1 parent
bb36afa
commit b45d54a
Showing
4 changed files
with
71 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
id: platformcolor | ||
title: PlatformColor | ||
--- | ||
|
||
``` | ||
PlatformColor(color1, [color2, ...colorN]) | ||
``` | ||
|
||
Use the `PlatformColor` function to access native colors on the target platform via supplying the native color’s corresponding string value. You pass a string to the `PlatformColor` function, and provided it exists on that platform, that native color will be applied to the control or Javascript component specified in your style. All native color logic also translates if applicable, meaning if the native color specified is themes and/or high contrast sensitive, that logic will also transfer to the JavaScript component being colored. | ||
|
||
For a full list of the types of system colors supported, see: | ||
|
||
- [Android R.attr](https://developer.android.com/reference/android/R.attr) | ||
- [iOS Color](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/) | ||
|
||
## Example | ||
|
||
``` | ||
import React from 'react'; | ||
import { Text, View, StyleSheet, PlatformColor, Platform } from 'react-native'; | ||
export default function App() { | ||
return ( | ||
<View> | ||
<Text style={styles.labelCell}> | ||
I am a special label color! | ||
</Text> | ||
</View> | ||
); | ||
} | ||
const styles = StyleSheet.create({ | ||
labelCell: { | ||
flex: 1, | ||
alignItems: 'stretch', | ||
...Platform.select({ | ||
ios: {color: PlatformColor('labelColor')}, | ||
android: {color: PlatformColor('?attr/colorControlNormal')}, | ||
default: {color: 'black'}, | ||
}), | ||
}, | ||
}); | ||
``` | ||
|
||
The string value provided to the `PlatformColor` function must match and agree with the same string as it exists on the native platform the app is being run on. This means to avoid runtime errors the function should be wrapped in a platform check, either through a `Platform.OS === 'platform'` or a `Platform.Select()`. | ||
|
||
You can find a complete example that demonstrates proper, intended use of PlatformColor in [PlatformColorExample.js](https://github.com/facebook/react-native/blob/master/RNTester/js/examples/PlatformColor/PlatformColorExample.js). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,7 @@ | |
"linking", | ||
"panresponder", | ||
"pixelratio", | ||
"platformcolor", | ||
"share", | ||
"stylesheet", | ||
"systrace", | ||
|