11/* eslint-disable max-depth */
22import { Dimensions , Platform } from 'react-native'
3+ import { Platform as UniwindPlatform , UNIWIND_PLATFORM_VARIABLES , UNIWIND_THEME_VARIABLES } from '../../common/consts'
34import { Orientation , StyleDependency } from '../../types'
45import { UniwindListener } from '../listener'
56import { ComponentState , GenerateStyleSheetsCallback , RNStyle , Style , StyleSheets , ThemeName , UniwindContextType } from '../types'
@@ -61,7 +62,14 @@ class UniwindStoreBuilder {
6162 reinit = ( generateStyleSheetCallback : GenerateStyleSheetsCallback , themes : Array < string > ) => {
6263 const config = generateStyleSheetCallback ( this . runtime )
6364 const { scopedVars, stylesheet, vars } = config
64- const platformVars = scopedVars [ `__uniwind-platform-${ Platform . OS } ` ]
65+ const platform = this . getCurrentPlatform ( )
66+ const commonPlatform = platform . includes ( 'tv' ) ? UniwindPlatform . TV : UniwindPlatform . Native
67+ const commonPlatformVars = scopedVars [ `${ UNIWIND_PLATFORM_VARIABLES } ${ commonPlatform } ` ]
68+ const platformVars = scopedVars [ `${ UNIWIND_PLATFORM_VARIABLES } ${ platform } ` ]
69+
70+ if ( commonPlatformVars ) {
71+ Object . defineProperties ( vars , Object . getOwnPropertyDescriptors ( commonPlatformVars ) )
72+ }
6573
6674 if ( platformVars ) {
6775 Object . defineProperties ( vars , Object . getOwnPropertyDescriptors ( platformVars ) )
@@ -70,7 +78,7 @@ class UniwindStoreBuilder {
7078 this . stylesheet = stylesheet
7179 this . vars = Object . fromEntries ( themes . map ( theme => {
7280 const clonedVars = cloneWithAccessors ( vars )
73- const themeVars = scopedVars [ `__uniwind-theme- ${ theme } ` ]
81+ const themeVars = scopedVars [ `${ UNIWIND_THEME_VARIABLES } ${ theme } ` ]
7482
7583 if ( themeVars ) {
7684 Object . defineProperties ( clonedVars , Object . getOwnPropertyDescriptors ( themeVars ) )
@@ -276,6 +284,20 @@ class UniwindStoreBuilder {
276284
277285 return true
278286 }
287+
288+ private getCurrentPlatform ( ) {
289+ const platform = Platform . OS
290+
291+ if ( platform === 'android' ) {
292+ return Platform . isTV ? UniwindPlatform . AndroidTV : UniwindPlatform . Android
293+ }
294+
295+ if ( platform === 'ios' ) {
296+ return Platform . isTV ? UniwindPlatform . AppleTV : UniwindPlatform . iOS
297+ }
298+
299+ return platform
300+ }
279301}
280302
281303export const UniwindStore = new UniwindStoreBuilder ( )
0 commit comments