Merge pull request #2264 from ecency/nt/auto-detect-theme

Nt/auto detect theme
This commit is contained in:
Feruz M 2022-04-15 18:35:45 +03:00 committed by GitHub
commit 5200264343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

@ -36,6 +36,7 @@ public class MainActivity extends ReactActivity {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getReactInstanceManager().onConfigurationChanged(this, newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent); }

View File

@ -1,5 +1,5 @@
import { Component } from 'react';
import { Platform, BackHandler, Alert, Linking, AppState } from 'react-native';
import { Platform, BackHandler, Alert, Linking, AppState, Appearance } from 'react-native';
import NetInfo from '@react-native-community/netinfo';
import Config from 'react-native-config';
import get from 'lodash/get';
@ -121,6 +121,7 @@ export const setPreviousAppState = () => {
let firebaseOnNotificationOpenedAppListener = null;
let firebaseOnMessageListener = null;
let removeAppearanceListener = null;
let scAccounts = [];
class ApplicationContainer extends Component {
@ -152,13 +153,14 @@ class ApplicationContainer extends Component {
AppState.addEventListener('change', this._handleAppStateChange);
setPreviousAppState();
/*if (nativeThemeEventEmitter) {
nativeThemeEventEmitter.on('currentModeChanged', (newMode) => {
const { dispatch } = this.props;
//use Appearance.addChangeListener here to change app theme on the fly
//native side reference: https://github.com/facebook/react-native/issues/28823#issuecomment-642032481
this.removeAppearanceListener = Appearance.addChangeListener(({ colorScheme }) => {
console.log('OS color scheme changed', colorScheme);
const _isDarkMode = colorScheme === 'dark';
dispatch(isDarkTheme(_isDarkMode));
});
dispatch(isDarkTheme(newMode === 'dark'));
});
}*/
this._createPushListener();
if (!isIos) BackHandler.addEventListener('hardwareBackPress', this._onBackPress);
@ -256,6 +258,10 @@ class ApplicationContainer extends Component {
firebaseOnNotificationOpenedAppListener();
}
if (removeAppearanceListener) {
removeAppearanceListener();
}
this.netListener();
}
@ -787,7 +793,7 @@ class ApplicationContainer extends Component {
const settings = await getSettings();
if (settings) {
const isDarkMode = false; //useDarkMode();
const isDarkMode = Appearance.getColorScheme() === 'dark';
dispatch(isDarkTheme(settings.isDarkTheme !== null ? settings.isDarkTheme : isDarkMode));
this.setState({
isThemeReady: true,

View File

@ -1,11 +1,10 @@
import React from 'react';
import { View } from 'react-native';
import { View, Appearance } from 'react-native';
import LottieView from 'lottie-react-native';
import { useDarkMode } from 'react-native-dynamic';
import styles from './launchStyles';
const LaunchScreen = () => {
const isDarkMode = useDarkMode();
const isDarkMode = Appearance.getColorScheme() === 'dark';
return (
<View style={isDarkMode ? styles.darkContainer : styles.container}>
<LottieView