| 23 | export type DynamicImageStyle = DynamicStyle<ImageStyle> |
| 24 | |
| 25 | function parseStylesFor<T extends DynamicStyles<T>>(styles: T, mode: Mode): NormalizeStyles<T> { |
| 26 | const newStyles: IndexedObject<IndexedObject<ValueOf<ValueOf<T>>>> = {} |
| 27 | |
| 28 | let containsDynamicValues = false |
| 29 | |
| 30 | for (const i in styles) { |
| 31 | const style = styles[i] |
| 32 | type Value = ValueOf<ValueOf<T>> |
| 33 | const newStyle: IndexedObject<Value> = {} |
| 34 | for (const i in style) { |
| 35 | const value = style[i] |
| 36 | |
| 37 | if (value instanceof DynamicValue) { |
| 38 | containsDynamicValues = true |
| 39 | newStyle[i] = value[mode] |
| 40 | } else { |
| 41 | newStyle[i] = value as Value |
| 42 | } |
| 43 | } |
| 44 | newStyles[i] = newStyle |
| 45 | } |
| 46 | |
| 47 | if (!containsDynamicValues && process.env.NODE_ENV !== 'production') { |
| 48 | console.warn( |
| 49 | 'A DynamicStyleSheet was used without any DynamicValues. Consider replacing with a regular StyleSheet.', |
| 50 | ) |
| 51 | } |
| 52 | |
| 53 | return (newStyles as unknown) as NormalizeStyles<T> |
| 54 | } |
| 55 | |
| 56 | export class DynamicStyleSheet<T extends DynamicStyles<T>> { |
| 57 | public readonly dark: NormalizeStyles<T> |