-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathutils.ts
More file actions
61 lines (51 loc) · 1.45 KB
/
utils.ts
File metadata and controls
61 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useRef } from 'react'
import { DefaultTheme, MD3DarkTheme, useTheme } from 'react-native-paper'
import Color from 'color'
export const supportedOrientations: (
| 'portrait'
| 'portrait-upside-down'
| 'landscape'
| 'landscape-left'
| 'landscape-right'
)[] = [
'portrait',
'portrait-upside-down',
'landscape',
'landscape-left',
'landscape-right',
]
export type PaperTheme = typeof MD3DarkTheme | typeof DefaultTheme
export function useLatest<T>(value: T) {
const ref = useRef(value)
ref.current = value
return ref
}
export function useHeaderBackgroundColor() {
const theme = useTheme()
return theme.colors.surface
}
export function useHeaderTextColor() {
const theme = useTheme()
return theme.colors.onSurfaceVariant
}
export function useTextColorOnPrimary() {
const theme = useTheme()
const isDark = !Color(theme.colors.primary).isLight()
if (isDark && theme.dark) {
return theme.colors.onSurface
}
return theme.colors.onPrimary
}
export function range(start: number, end: number) {
return Array(end - start + 1)
.fill(null)
.map((_, i) => start + i)
}
export function lightenBy(color: InstanceType<typeof Color>, ratio: number) {
const lightness = color.lightness()
return color.lightness(lightness + (100 - lightness) * ratio)
}
export function darkenBy(color: InstanceType<typeof Color>, ratio: number) {
const lightness = color.lightness()
return color.lightness(lightness - lightness * ratio)
}