Replace settings context with theme context
The settings context was having a big performance impact on the app. We only truly need the theme + color to be a global context.typeorm
parent
8d7fe149f5
commit
31f1528c35
@ -1,11 +1,11 @@
|
||||
import {useColorScheme} from 'react-native'
|
||||
import {useSettings} from './use-settings'
|
||||
import {useTheme} from './use-theme'
|
||||
|
||||
export default function useDark() {
|
||||
const dark = useColorScheme() === 'dark'
|
||||
const {settings} = useSettings()
|
||||
const {theme} = useTheme()
|
||||
|
||||
if (settings.theme === 'dark') return true
|
||||
if (settings.theme === 'light') return false
|
||||
if (theme === 'dark') return true
|
||||
if (theme === 'light') return false
|
||||
return dark
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
import React, {useContext} from 'react'
|
||||
import {darkColors} from './colors'
|
||||
import Settings from './settings'
|
||||
|
||||
export const defaultSettings: Settings = {
|
||||
alarm: true,
|
||||
color: darkColors[0].hex,
|
||||
date: '',
|
||||
images: true,
|
||||
notify: false,
|
||||
showDate: false,
|
||||
showSets: true,
|
||||
showUnit: true,
|
||||
sound: '',
|
||||
steps: false,
|
||||
theme: 'system',
|
||||
vibrate: true,
|
||||
noSound: false,
|
||||
}
|
||||
|
||||
export const SettingsContext = React.createContext<{
|
||||
settings: Settings
|
||||
setSettings: (value: Settings) => void
|
||||
}>({
|
||||
settings: defaultSettings,
|
||||
setSettings: () => null,
|
||||
})
|
||||
|
||||
export function useSettings() {
|
||||
return useContext(SettingsContext)
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import {createContext, useContext} from 'react'
|
||||
|
||||
export const ThemeContext = createContext<{
|
||||
theme: string
|
||||
color: string
|
||||
setTheme: (value: string) => void
|
||||
setColor: (value: string) => void
|
||||
}>({
|
||||
theme: '',
|
||||
color: '',
|
||||
setTheme: () => null,
|
||||
setColor: () => null,
|
||||
})
|
||||
|
||||
export function useTheme() {
|
||||
return useContext(ThemeContext)
|
||||
}
|
Loading…
Reference in New Issue