Skip to content
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

Update the root component to react functional component #6041

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
72 changes: 51 additions & 21 deletions app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React , {useRef,useEffect} from 'react';
import { Dimensions, EmitterSubscription, Linking } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider, initialWindowMetrics } from 'react-native-safe-area-context';
Expand Down Expand Up @@ -36,6 +36,7 @@ import { TSupportedThemes, ThemeContext } from './theme';
import ChangePasscodeView from './views/ChangePasscodeView';
import ScreenLockedView from './views/ScreenLockedView';


RNScreens.enableScreens();
initStore(store);

Expand Down Expand Up @@ -78,31 +79,54 @@ const parseDeepLinking = (url: string) => {
return null;
};

export default class Root extends React.Component<{}, IState> {
private listenerTimeout!: any;
private dimensionsListener?: EmitterSubscription;

constructor(props: any) {
super(props);
this.init();


const Root: React.FC = () => {
const stateRef = useRef({
theme: getTheme(initialTheme()),
themePreferences: initialTheme(),
...Dimensions.get('window'),
});

const listenerTimeout = useRef<any>(null);
const dimensionsListener = useRef<EmitterSubscription | undefined>(undefined);

const init = () => {
};

const initCrashReport = () => {
};

const initTablet = () => {
};


useEffect(() => {
init();

if (!isFDroidBuild) {
this.initCrashReport();
initCrashReport();
}
const { width, height, scale, fontScale } = Dimensions.get('window');
const theme = initialTheme();
this.state = {
theme: getTheme(theme),
themePreferences: theme,
width,
height,
scale,
fontScale
};

if (isTablet) {
this.initTablet();
initTablet();
}
setNativeTheme(theme);
}

setNativeTheme(stateRef.current.themePreferences);

return () => {
if (listenerTimeout.current) {
clearTimeout(listenerTimeout.current);
}
if (dimensionsListener.current) {
dimensionsListener.current.remove();
}
};
}, []);

};


componentDidMount() {
this.listenerTimeout = setTimeout(() => {
Expand All @@ -115,6 +139,9 @@ export default class Root extends React.Component<{}, IState> {
}, 5000);
this.dimensionsListener = Dimensions.addEventListener('change', this.onDimensionsChange);
}




componentWillUnmount() {
clearTimeout(this.listenerTimeout);
Expand Down Expand Up @@ -238,3 +265,6 @@ export default class Root extends React.Component<{}, IState> {
);
}
}


export default Root;
Loading