Skip to content

Scheme - fix color changing #2607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/commons/asBaseComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import hoistStatics from 'hoist-non-react-statics';
import * as Modifiers from './modifiers';
import {Scheme, ThemeManager} from '../style';
import {Scheme, SchemeChangeListener, ThemeManager} from '../style';
import forwardRef from './forwardRef';
import UIComponent from './UIComponent';

Expand All @@ -19,6 +19,7 @@ export interface AsBaseComponentOptions {
}

const EMPTY_MODIFIERS = {};
const colorScheme = Scheme.getSchemeType();

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

state = {
error: false
error: false,
colorScheme
};

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

appearanceListener = () => {
appearanceListener = (colorScheme: Parameters<SchemeChangeListener>['0']) => {
// iOS 13 and above will trigger this call with the wrong colorScheme value. So just ignore returned colorScheme for now
// https://github.com/facebook/react-native/issues/28525
// this.setState({colorScheme: Appearance.getColorScheme()});
this.setState({colorScheme: Scheme.getSchemeType()});
if (this.state.colorScheme !== colorScheme) {
this.setState({colorScheme});
}
};

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