-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
106 lines (83 loc) · 2.89 KB
/
types.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { Component, ComponentType } from 'react'
import {
ViewStyle,
TextStyle,
ImageStyle,
ViewProps,
TextProps,
ImageProps,
ButtonProps,
TextInputProps,
TouchableOpacityProps,
Animated,
View,
PressableProps,
ScrollViewProps,
} from 'react-native'
export interface Scale {
minimum: number
maximum: number
factor: number
}
export interface CustomBreakpoints {}
export interface DefaultBreakpoints {
small: number
medium: number
large: number
}
export type CurrentBreakpoints = keyof CustomBreakpoints extends never ? DefaultBreakpoints : CustomBreakpoints
export type BreakpointKeys = (keyof CurrentBreakpoints)[]
export type Orientation = 'portrait' | 'landscape'
export type Value = (value: number, breakpoint: string, orientation: Orientation) => number
export type StyledComponent = string | string[] | Function | Component
export type NativeStyle = ViewStyle & TextStyle & ImageStyle
export type Platform = 'ios' | 'android'
export type PlatformStyleProp<T extends keyof NativeStyle, K extends Platform = Platform> = {
[P in K]: NativeStyle[T] | MediaStyleProp<T> | OrientationStyleProp<T>
}
export type MediaStyleProp<
T extends keyof NativeStyle,
U extends keyof CurrentBreakpoints = keyof CurrentBreakpoints,
> = {
[K in U]?: NativeStyle[T] | PlatformStyleProp<T> | OrientationStyleProp<T>
}
export type OrientationStyleProp<T extends keyof NativeStyle> = [
NativeStyle[T] | PlatformStyleProp<T> | MediaStyleProp<T>,
NativeStyle[T] | PlatformStyleProp<T> | MediaStyleProp<T>,
]
export type StyleValue<L extends keyof NativeStyle> =
| NativeStyle[L]
| PlatformStyleProp<L>
| MediaStyleProp<L>
| OrientationStyleProp<L>
export type StyleProps<T extends keyof NativeStyle> = {
[L in T]?: StyleValue<L>
}
export type StyleSheet<K extends string, T extends Record<K, NativeStyle>> = {
[P in K]: {
[L in keyof T[P] & keyof NativeStyle]?: T[P][L] | PlatformStyleProp<L> | MediaStyleProp<L> | OrientationStyleProp<L>
}
}
export type StyleSheetFlat<K extends string, T extends Record<K, NativeStyle>> = T
export type StyledSheet<T extends NativeStyle> = {
[L in keyof T & keyof NativeStyle]?: T[L] | PlatformStyleProp<L> | MediaStyleProp<L> | OrientationStyleProp<L>
}
export type StyledSheetFlat<T extends NativeStyle> = T
export type Conditionals = keyof CurrentBreakpoints | Platform | Orientation
export type ComponentInput = keyof StringComponentProps | typeof Component | ComponentType
export type StringComponentProps = {
View: ViewProps
Text: TextProps
Image: ImageProps
Button: ButtonProps
TextInput: TextInputProps
ScrollView: ScrollViewProps
TouchableOpacity: TouchableOpacityProps
'Animated.View': Animated.AnimatedComponent<typeof View>
Pressable: PressableProps
}
export type ComponentProps<T extends ComponentInput> = T extends keyof StringComponentProps
? StringComponentProps[T]
: T extends Component
? T['props']
: never