MCPcopy Create free account
hub / github.com/codemotionapps/react-native-dynamic / parseStylesFor

Function parseStylesFor

library/src/dynamic-style-sheet.ts:25–54  ·  view source on GitHub ↗
(styles: T, mode: Mode)

Source from the content-addressed store, hash-verified

23export type DynamicImageStyle = DynamicStyle<ImageStyle>
24
25function 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
56export class DynamicStyleSheet<T extends DynamicStyles<T>> {
57 public readonly dark: NormalizeStyles<T>

Callers 1

constructorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected