1
1
import React from 'react' ;
2
2
import hoistStatics from 'hoist-non-react-statics' ;
3
3
import * as Modifiers from './modifiers' ;
4
- import { Scheme , ThemeManager } from '../style' ;
4
+ import { Scheme , SchemeChangeListener , ThemeManager } from '../style' ;
5
5
import forwardRef from './forwardRef' ;
6
6
import UIComponent from './UIComponent' ;
7
7
@@ -19,6 +19,7 @@ export interface AsBaseComponentOptions {
19
19
}
20
20
21
21
const EMPTY_MODIFIERS = { } ;
22
+ const colorScheme = Scheme . getSchemeType ( ) ;
22
23
23
24
function asBaseComponent < PROPS , STATICS = { } > ( WrappedComponent : React . ComponentType < any > ,
24
25
options : AsBaseComponentOptions = { } ) : React . ComponentClass < PROPS & ThemeComponent > & STATICS {
@@ -28,7 +29,8 @@ function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentT
28
29
static defaultProps : any ;
29
30
30
31
state = {
31
- error : false
32
+ error : false ,
33
+ colorScheme
32
34
} ;
33
35
34
36
componentDidMount ( ) {
@@ -39,11 +41,13 @@ function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentT
39
41
Scheme . removeChangeListener ( this . appearanceListener ) ;
40
42
}
41
43
42
- appearanceListener = ( ) => {
44
+ appearanceListener : SchemeChangeListener = ( colorScheme ) => {
43
45
// iOS 13 and above will trigger this call with the wrong colorScheme value. So just ignore returned colorScheme for now
44
46
// https://github.com/facebook/react-native/issues/28525
45
47
// this.setState({colorScheme: Appearance.getColorScheme()});
46
- this . setState ( { colorScheme : Scheme . getSchemeType ( ) } ) ;
48
+ if ( this . state . colorScheme !== colorScheme ) {
49
+ this . setState ( { colorScheme} ) ;
50
+ }
47
51
} ;
48
52
49
53
static getThemeProps = ( props : any , context : any ) => {
0 commit comments