-
Notifications
You must be signed in to change notification settings - Fork 734
POC for dark mode support #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
f06c22d
947daeb
9168100
5657c9a
f71b3c7
2495b7c
7c59fe1
5e8685d
43b4686
fc22258
2307d0c
9f37b73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, {Component} from 'react'; | ||
import {StyleSheet} from 'react-native'; | ||
import {View, Text, Constants} from 'react-native-ui-lib'; | ||
|
||
class DarkModeScreen extends Component { | ||
state = {}; | ||
render() { | ||
return ( | ||
<View flex padding-page bg-screenBG> | ||
<Text h1 textColor> | ||
Dark Mode | ||
</Text> | ||
{Constants.isIOS ? ( | ||
<Text marginT-s2 body textColor> | ||
Change to dark mode in simulator by pressing Cmd+Shift+A | ||
</Text> | ||
) : ( | ||
<Text>Change to dark mode</Text> | ||
)} | ||
|
||
<View style={styles.moonOrSun} bg-moonOrSun/> | ||
<View style={[styles.mountain, styles.mountainBackground]} bg-mountainBackground/> | ||
<View style={[styles.mountain, styles.mountainForeground]} bg-mountainForeground/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
mountain: { | ||
position: 'absolute', | ||
width: 1000, | ||
height: 1000, | ||
borderRadius: 500 | ||
}, | ||
mountainForeground: { | ||
left: -500, | ||
bottom: -800 | ||
}, | ||
mountainBackground: { | ||
right: -500, | ||
bottom: -850 | ||
}, | ||
moonOrSun: { | ||
position: 'absolute', | ||
right: 50, | ||
bottom: 350, | ||
width: 100, | ||
height: 100, | ||
borderRadius: 50 | ||
} | ||
}); | ||
|
||
export default DarkModeScreen; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import _ from 'lodash'; | ||
import {StyleSheet} from 'react-native'; | ||
import {Appearance, StyleSheet} from 'react-native'; | ||
import {Typography, Colors, BorderRadiuses, Spacings, ThemeManager} from '../style'; | ||
import {BorderRadiusesLiterals} from '../style/borderRadiuses'; | ||
import TypographyPresets from '../style/typographyPresets'; | ||
|
@@ -96,26 +96,28 @@ export type ContainerModifiers = | |
BorderRadiusModifiers & | ||
BackgroundColorModifier; | ||
|
||
|
||
export function extractColorValue(props: Dictionary<any>) { | ||
// const props = this.getThemeProps(); | ||
const allColorsKeys: Array<keyof typeof Colors> = _.keys(Colors); | ||
const scheme = Appearance.getColorScheme() || 'light'; | ||
const schemeColors = Colors.schemes[scheme!]; | ||
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. How do you know 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. I added a default to 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. I'm not sure why but this is the definition in react-native:
Actually it's more weird because the original code does not have them (does not seem to have changed in the last two years)... BTW, you can now remove the 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. fixed |
||
const allColorsKeys: Array<keyof typeof Colors> = [..._.keys(Colors), ..._.keys(schemeColors)]; | ||
const colorPropsKeys = _.chain(props) | ||
.keys() | ||
.filter(key => _.includes(allColorsKeys, key)) | ||
.value(); | ||
const color = _.findLast(colorPropsKeys, colorKey => props[colorKey] === true)!; | ||
return Colors[color]; | ||
const colorKey = _.findLast(colorPropsKeys, colorKey => props[colorKey] === true)!; | ||
return schemeColors[colorKey] || Colors[colorKey]; | ||
} | ||
|
||
export function extractBackgroundColorValue(props: Dictionary<any>) { | ||
let backgroundColor; | ||
const scheme = Appearance.getColorScheme() || 'light'; | ||
const schemeColors = Colors.schemes[scheme!]; | ||
|
||
const keys = Object.keys(props); | ||
const bgProp = _.findLast(keys, prop => Colors.getBackgroundKeysPattern().test(prop) && !!props[prop])!; | ||
if (props[bgProp]) { | ||
const key = bgProp.replace(Colors.getBackgroundKeysPattern(), ''); | ||
backgroundColor = Colors[key]; | ||
backgroundColor = schemeColors[key] || Colors[key]; | ||
} | ||
|
||
return backgroundColor; | ||
|
Uh oh!
There was an error while loading. Please reload this page.