Skip to content

Commit

Permalink
add auto mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SorinC6 committed May 3, 2024
1 parent d70d283 commit 5360daf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import {StyleSheet, TouchableOpacity, View} from 'react-native'
import {Icon} from '../../../components/Icon'
import {Text} from '../../../components/Text'
import {themeNames} from '../../../i18n/global-messages'
import {useThemeStorageMaker} from '../../../yoroi-wallets/hooks'

type Props = {
title: SupportedThemes
selectTheme: (name: SupportedThemes) => void
isSelected: boolean
setLocalTheme: (name: SupportedThemes) => void
}

export const ThemePickerItem = ({title, selectTheme, isSelected}: Props) => {
export const ThemePickerItem = ({title, selectTheme, setLocalTheme}: Props) => {
const {colors} = useStyles()
const strings = useStrings()
const themeStorage = useThemeStorageMaker()

const handleSelectTheme = (theme: SupportedThemes) => {
setLocalTheme(theme)
selectTheme(theme)
}
return (
Expand All @@ -27,7 +30,7 @@ export const ThemePickerItem = ({title, selectTheme, isSelected}: Props) => {
<Title>{strings.translateThemeName(title)}</Title>
</Description>

<Selected>{isSelected && <Icon.Check size={24} color={colors.checkIcon} />}</Selected>
<Selected>{themeStorage.read() === title && <Icon.Check size={24} color={colors.checkIcon} />}</Selected>
</Row>
</TouchableOpacity>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import {useTheme} from '@yoroi/theme'
import React from 'react'
import {FlatList, StyleSheet} from 'react-native'

import {useThemeStorageMaker} from '../../../yoroi-wallets/hooks'
import {ThemePickerItem} from './ThemePickerItem'

export const ThemePickerList = () => {
const {name, selectThemeName, data} = useTheme()
const themeStorage = useThemeStorageMaker()
const [_, setLocalTheme] = React.useState(themeStorage.read())
const {selectThemeName, data} = useTheme()

return (
<FlatList
contentContainerStyle={styles.contentContainer}
data={data}
keyExtractor={({themeName}) => themeName}
renderItem={({item: {themeName}}) => {
console.log('ThemePickerList themeName', themeName)
return <ThemePickerItem isSelected={themeName === name} title={themeName} selectTheme={selectThemeName} />
return <ThemePickerItem title={themeName} selectTheme={selectThemeName} setLocalTheme={setLocalTheme} />
}}
/>
)
Expand Down
7 changes: 6 additions & 1 deletion packages/theme/src/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {useColorScheme} from 'react-native'
import {ColorSchemeName, useColorScheme as _useColorScheme} from 'react-native'

import {ThemedPalette, SupportedThemes, Theme, ThemeStorage} from './types'
import {defaultLightTheme} from './themes/default-light'
Expand Down Expand Up @@ -70,6 +70,7 @@ type ThemeContext = {
isLight: boolean
isDark: boolean
atoms: Atoms
data: ThemeType[]
}

const themes: Record<Exclude<SupportedThemes, 'system'>, Theme> = {
Expand All @@ -80,3 +81,7 @@ const themes: Record<Exclude<SupportedThemes, 'system'>, Theme> = {
const missingProvider = () => {
throw new Error('ThemeProvider is missing')
}

const useColorScheme = (): NonNullable<ColorSchemeName> => {
return _useColorScheme() as NonNullable<ColorSchemeName>
}
45 changes: 8 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f"
integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==

"@babel/helper-string-parser@^7.23.4":
version "7.24.1"
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.24.1.tgz#f99c36d3593db9540705d0739a1f10b5e20c696e"
integrity sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==

"@babel/helper-validator-identifier@^7.22.20":
version "7.22.20"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz#c4ae002c61d2879e724581d96665583dbc1dc0e0"
Expand Down Expand Up @@ -1734,15 +1739,6 @@
"@babel/helper-validator-identifier" "^7.22.20"
to-fast-properties "^2.0.0"

"@babel/types@^7.22.19":
version "7.23.6"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.6.tgz#be33fdb151e1f5a56877d704492c240fc71c7ccd"
integrity sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==
dependencies:
"@babel/helper-string-parser" "^7.23.4"
"@babel/helper-validator-identifier" "^7.22.20"
to-fast-properties "^2.0.0"

"@babel/types@^7.23.6":
version "7.23.9"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.9.tgz#1dd7b59a9a2b5c87f8b41e52770b5ecbf492e002"
Expand Down Expand Up @@ -21094,16 +21090,7 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -21216,7 +21203,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -21244,13 +21231,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -22873,7 +22853,7 @@ workerpool@6.2.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down Expand Up @@ -22909,15 +22889,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
Expand Down

0 comments on commit 5360daf

Please sign in to comment.