Skip to content

Commit e48a2eb

Browse files
Scheme - fix color changing (#2607)
* Scheme - fix flickering * Update src/commons/asBaseComponent.tsx Co-authored-by: Ethan Sharabi <[email protected]> --------- Co-authored-by: Ethan Sharabi <[email protected]>
1 parent 5376abc commit e48a2eb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/commons/asBaseComponent.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import hoistStatics from 'hoist-non-react-statics';
33
import * as Modifiers from './modifiers';
4-
import {Scheme, ThemeManager} from '../style';
4+
import {Scheme, SchemeChangeListener, ThemeManager} from '../style';
55
import forwardRef from './forwardRef';
66
import UIComponent from './UIComponent';
77

@@ -19,6 +19,7 @@ export interface AsBaseComponentOptions {
1919
}
2020

2121
const EMPTY_MODIFIERS = {};
22+
const colorScheme = Scheme.getSchemeType();
2223

2324
function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentType<any>,
2425
options: AsBaseComponentOptions = {}): React.ComponentClass<PROPS & ThemeComponent> & STATICS {
@@ -28,7 +29,8 @@ function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentT
2829
static defaultProps: any;
2930

3031
state = {
31-
error: false
32+
error: false,
33+
colorScheme
3234
};
3335

3436
componentDidMount() {
@@ -39,11 +41,13 @@ function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentT
3941
Scheme.removeChangeListener(this.appearanceListener);
4042
}
4143

42-
appearanceListener = () => {
44+
appearanceListener: SchemeChangeListener = (colorScheme) => {
4345
// iOS 13 and above will trigger this call with the wrong colorScheme value. So just ignore returned colorScheme for now
4446
// https://github.com/facebook/react-native/issues/28525
4547
// this.setState({colorScheme: Appearance.getColorScheme()});
46-
this.setState({colorScheme: Scheme.getSchemeType()});
48+
if (this.state.colorScheme !== colorScheme) {
49+
this.setState({colorScheme});
50+
}
4751
};
4852

4953
static getThemeProps = (props: any, context: any) => {

0 commit comments

Comments
 (0)