forked from vergnet/application-amicale
Fix crash on app start
This commit is contained in:
parent
c5287611c4
commit
f5233c53f8
6 changed files with 63 additions and 51 deletions
6
App.tsx
6
App.tsx
|
@ -55,7 +55,7 @@ type StateType = {
|
|||
currentTheme: ReactNativePaper.Theme | undefined;
|
||||
};
|
||||
|
||||
export default class App extends React.Component<null, StateType> {
|
||||
export default class App extends React.Component<{}, StateType> {
|
||||
navigatorRef: {current: null | NavigationContainerRef};
|
||||
|
||||
defaultHomeRoute: string | null;
|
||||
|
@ -64,8 +64,8 @@ export default class App extends React.Component<null, StateType> {
|
|||
|
||||
urlHandler: URLHandler;
|
||||
|
||||
constructor() {
|
||||
super(null);
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isLoading: true,
|
||||
showIntro: true,
|
||||
|
|
|
@ -284,5 +284,9 @@ type PropsType = {
|
|||
};
|
||||
|
||||
export default function MainNavigator(props: PropsType) {
|
||||
return <MainStackComponent createTabNavigator={() => TabNavigator(props)} />;
|
||||
return (
|
||||
<MainStackComponent
|
||||
createTabNavigator={() => <TabNavigator {...props} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ function HomeStackComponent(
|
|||
defaultData: {[key: string]: string},
|
||||
) {
|
||||
let params;
|
||||
if (initialRoute != null) {
|
||||
if (initialRoute) {
|
||||
params = {data: defaultData, nextScreen: initialRoute, shouldOpen: true};
|
||||
}
|
||||
const {colors} = useTheme();
|
||||
|
@ -255,19 +255,26 @@ type PropsType = {
|
|||
defaultHomeData: {[key: string]: string};
|
||||
};
|
||||
|
||||
export default function TabNavigator(props: PropsType) {
|
||||
let defaultRoute = 'home';
|
||||
export default class TabNavigator extends React.Component<PropsType> {
|
||||
defaultRoute: string;
|
||||
createHomeStackComponent: () => any;
|
||||
|
||||
constructor(props: PropsType) {
|
||||
super(props);
|
||||
this.defaultRoute = 'home';
|
||||
if (!props.defaultHomeRoute) {
|
||||
defaultRoute = AsyncStorageManager.getString(
|
||||
this.defaultRoute = AsyncStorageManager.getString(
|
||||
AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
|
||||
).toLowerCase();
|
||||
}
|
||||
const createHomeStackComponent = () =>
|
||||
this.createHomeStackComponent = () =>
|
||||
HomeStackComponent(props.defaultHomeRoute, props.defaultHomeData);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Tab.Navigator
|
||||
initialRouteName={defaultRoute}
|
||||
initialRouteName={this.defaultRoute}
|
||||
tabBar={(tabProps) => <CustomTabBar {...tabProps} />}>
|
||||
<Tab.Screen
|
||||
name="services"
|
||||
|
@ -281,7 +288,7 @@ export default function TabNavigator(props: PropsType) {
|
|||
/>
|
||||
<Tab.Screen
|
||||
name="home"
|
||||
component={createHomeStackComponent}
|
||||
component={this.createHomeStackComponent}
|
||||
options={{title: i18n.t('screens.home.title')}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
|
@ -296,4 +303,5 @@ export default function TabNavigator(props: PropsType) {
|
|||
/>
|
||||
</Tab.Navigator>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ const LIST_ITEM_HEIGHT = 64;
|
|||
export default class AboutDependenciesScreen extends React.Component<{}> {
|
||||
data: Array<ListItemType>;
|
||||
|
||||
constructor() {
|
||||
super({});
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
this.data = generateListFromObject(packageJson.dependencies);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ class AmicaleContactScreen extends React.Component<{}> {
|
|||
// Dataset containing information about contacts
|
||||
CONTACT_DATASET: Array<DatasetItemType>;
|
||||
|
||||
constructor() {
|
||||
super({});
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
this.CONTACT_DATASET = [
|
||||
{
|
||||
name: i18n.t('screens.amicaleAbout.roles.interSchools'),
|
||||
|
|
|
@ -55,8 +55,8 @@ const styles = StyleSheet.create({
|
|||
type PermissionResults = 'unavailable' | 'denied' | 'blocked' | 'granted';
|
||||
|
||||
class ScannerScreen extends React.Component<{}, StateType> {
|
||||
constructor() {
|
||||
super({});
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
this.state = {
|
||||
hasPermission: false,
|
||||
scanned: false,
|
||||
|
|
Loading…
Reference in a new issue