mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 20:01:56 +03:00
Merge pull request #2264 from ecency/nt/auto-detect-theme
Nt/auto detect theme
This commit is contained in:
commit
5200264343
@ -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); }
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user