11/* eslint-disable max-depth */
22import { Dimensions , Platform } from 'react-native'
33import { Orientation , StyleDependency } from '../../types'
4- import { ComponentState , RNStyle , Style , StyleSheets } from '../types'
4+ import { ComponentState , GenerateStyleSheetsCallback , RNStyle , Style , StyleSheets } from '../types'
55import { parseBoxShadow , parseFontVariant , parseTransformsMutation , resolveGradient } from './parsers'
66import { UniwindRuntime } from './runtime'
77
@@ -10,7 +10,7 @@ type StylesResult = {
1010 dependencies : Array < StyleDependency >
1111}
1212
13- export class UniwindStoreBuilder {
13+ class UniwindStoreBuilder {
1414 stylesheets = { } as StyleSheets
1515 listeners = {
1616 [ StyleDependency . ColorScheme ] : new Set < ( ) => void > ( ) ,
@@ -21,7 +21,6 @@ export class UniwindStoreBuilder {
2121 [ StyleDependency . FontScale ] : new Set < ( ) => void > ( ) ,
2222 [ StyleDependency . Rtl ] : new Set < ( ) => void > ( ) ,
2323 }
24- initialized = false
2524 runtime = UniwindRuntime
2625 cache = new Map < string , StylesResult > ( )
2726
@@ -51,11 +50,6 @@ export class UniwindStoreBuilder {
5150 return this . cache . get ( cacheKey ) !
5251 }
5352
54- if ( ! this . initialized ) {
55- this . initialized = true
56- this . reload ( )
57- }
58-
5953 const result = this . resolveStyles ( className , state )
6054
6155 this . cache . set ( cacheKey , result )
@@ -70,8 +64,8 @@ export class UniwindStoreBuilder {
7064 return result
7165 }
7266
73- reload = ( ) => {
74- const styleSheet = globalThis . __uniwind__computeStylesheet ( this . runtime )
67+ reinit = ( generateStyleSheetCallback ?: GenerateStyleSheetsCallback ) => {
68+ const styleSheet = generateStyleSheetCallback ?. ( this . runtime ) ?? this . stylesheets
7569 const themeVars = styleSheet [ `__uniwind-theme-${ this . runtime . currentThemeName } ` ]
7670 const platformVars = styleSheet [ `__uniwind-platform-${ Platform . OS } ` ]
7771
@@ -211,13 +205,6 @@ export class UniwindStoreBuilder {
211205
212206export const UniwindStore = new UniwindStoreBuilder ( )
213207
214- if ( __DEV__ ) {
215- globalThis . __uniwind__hot_reload = ( ) => {
216- UniwindStore . reload ( )
217- UniwindStore . notifyListeners ( [ StyleDependency . Theme ] )
218- }
219- }
220-
221208Dimensions . addEventListener ( 'change' , ( { window } ) => {
222209 const newOrientation = window . width > window . height ? Orientation . Landscape : Orientation . Portrait
223210 const orientationChanged = UniwindStore . runtime . orientation !== newOrientation
0 commit comments