-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow strict-local | ||
*/ | ||
// [TODO(macOS ISS#2323203) | ||
'use strict'; | ||
|
||
import type {ColorValue} from './StyleSheetTypes'; | ||
import {DynamicColorMacOSPrivate} from './PlatformColorValueTypes'; | ||
|
||
export type DynamicColorMacOSTuple = { | ||
light: ColorValue, | ||
dark: ColorValue, | ||
}; | ||
|
||
export const DynamicColorMacOS = ( | ||
tuple: DynamicColorMacOSTuple, | ||
): ColorValue => { | ||
return DynamicColorMacOSPrivate({light: tuple.light, dark: tuple.dark}); | ||
}; | ||
// ]TODO(macOS ISS#2323203) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import Platform from '../../../../Libraries/Utilities/Platform'; | |
const { | ||
ColorAndroid, | ||
DynamicColorIOS, | ||
DynamicColorMacOS, | ||
PlatformColor, | ||
StyleSheet, | ||
Text, | ||
|
@@ -228,32 +229,37 @@ function FallbackColorsExample() { | |
} | ||
|
||
function DynamicColorsExample() { | ||
return Platform.OS === 'ios' ? ( | ||
// [TODO(OSS Candidate ISS#2710739) | ||
const dynamicColorFn = Platform.select({ | ||
ios: DynamicColorIOS, | ||
macos: DynamicColorMacOS, | ||
}); | ||
return dynamicColorFn !== undefined ? ( | ||
<View style={styles.column}> | ||
<View style={styles.row}> | ||
<Text style={styles.labelCell}> | ||
DynamicColorIOS({'{\n'} | ||
{dynamicColorFn.name}({'{\n'} | ||
{' '}light: 'red', dark: 'blue'{'\n'} | ||
{'}'}) | ||
</Text> | ||
<View | ||
style={{ | ||
...styles.colorCell, | ||
backgroundColor: DynamicColorIOS({light: 'red', dark: 'blue'}), | ||
backgroundColor: dynamicColorFn({light: 'red', dark: 'blue'}), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tom-un
Collaborator
|
||
}} | ||
/> | ||
</View> | ||
<View style={styles.row}> | ||
<Text style={styles.labelCell}> | ||
DynamicColorIOS({'{\n'} | ||
{dynamicColorFn.name}({'{\n'} | ||
{' '}light: PlatformColor('systemBlueColor'),{'\n'} | ||
{' '}dark: PlatformColor('systemRedColor'),{'\n'} | ||
{'}'}) | ||
</Text> | ||
<View | ||
style={{ | ||
...styles.colorCell, | ||
backgroundColor: DynamicColorIOS({ | ||
backgroundColor: dynamicColorFn({ | ||
light: PlatformColor('systemBlueColor'), | ||
dark: PlatformColor('systemRedColor'), | ||
}), | ||
|
@@ -264,6 +270,7 @@ function DynamicColorsExample() { | |
) : ( | ||
<Text style={styles.labelCell}>Not applicable on this platform</Text> | ||
); | ||
// ]TODO(OSS Candidate ISS#2710739) | ||
} | ||
|
||
function AndroidColorsExample() { | ||
|
@@ -289,17 +296,26 @@ function VariantColorsExample() { | |
<View style={styles.column}> | ||
<View style={styles.row}> | ||
<Text style={styles.labelCell}> | ||
{Platform.OS === 'ios' || Platform.OS === 'macos' // TODO(macOS ISS#2323203) | ||
? "DynamicColorIOS({light: 'red', dark: 'blue'})" | ||
: "ColorAndroid('?attr/colorAccent')"} | ||
{// [TODO(OSS Candidate ISS#2710739) | ||
Platform.select({ | ||
ios: "DynamicColorIOS({light: 'red', dark: 'blue'})", | ||
android: "ColorAndroid('?attr/colorAccent')", | ||
macos: "DynamicColorMacOS({light: 'red', dark: 'blue'})", | ||
}) | ||
// ]TODO(OSS Candidate ISS#2710739) | ||
} | ||
</Text> | ||
<View | ||
style={{ | ||
...styles.colorCell, | ||
backgroundColor: | ||
Platform.OS === 'ios' || Platform.OS === 'macos' // TODO(macOS ISS#2323203) | ||
Platform.OS === 'ios' | ||
? DynamicColorIOS({light: 'red', dark: 'blue'}) | ||
: ColorAndroid('?attr/colorAccent'), | ||
: // [TODO(macOS ISS#2323203) | ||
Platform.OS === 'macos' | ||
? DynamicColorMacOS({light: 'red', dark: 'blue'}) | ||
: // ]TODO(macOS ISS#2323203) | ||
ColorAndroid('?attr/colorAccent'), | ||
}} | ||
/> | ||
</View> | ||
|
Hmm...There is a lint rule that is supposed to keep this from being allowed. We wanted to make sure calls to
DynamicColorIOS
andPlatformColor
(and now probablyDynamicColorMacOS
) are statically analyzable so that there could be a build step that automatically pulls them out. This should fail the lint rule.cc @tom-un