Skip to content

Commit

Permalink
correct params access example
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed May 13, 2023
1 parent 00e0c5b commit 7accb37
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/screens/_screen-sample.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import React, {useEffect} from 'react';
import {ScrollView} from 'react-native';
import {View} from 'react-native-ui-lib';
import {Text, View} from 'react-native-ui-lib';
import {observer} from 'mobx-react';
import {useNavigation} from '@react-navigation/native';
import {useNavigation, useRoute} from '@react-navigation/native';
import {NavioScreen} from 'rn-navio';

import {services, useServices} from '@app/services';
import {useAppearance} from '@app/utils/hooks';
import {NavioSection} from '@app/components/sections/NavioSection';

export type Props = {
type?: 'push';
export type Params = {
type?: 'push' | 'show';
productId?: string;
};

export const Example: NavioScreen<Props> = observer(({type = 'push'}) => {
export const Example: NavioScreen = observer(() => {
useAppearance(); // for Dark Mode
const navigation = useNavigation();
const {params: _p} = useRoute(); // this is how to get passed params with navio.push('Screen', params)
const params = _p as Params; // use as params?.type
const {t, navio} = useServices();
// const {ui} = useStores();

Expand All @@ -38,6 +41,13 @@ export const Example: NavioScreen<Props> = observer(({type = 'push'}) => {
return (
<View flex bg-bgColor>
<ScrollView contentInsetAdjustmentBehavior="always">
{/* Product Page example related */}
{!!params?.productId ? (
<View margin-s2 marginV-s2 paddingH-s3>
<Text>ProductId: {params.productId}</Text>
</View>
) : null}

<NavioSection />
</ScrollView>
</View>
Expand All @@ -46,5 +56,5 @@ export const Example: NavioScreen<Props> = observer(({type = 'push'}) => {

Example.options = props => ({
headerBackTitleStyle: false,
title: `${services.t.do('example.title')} ${(props?.route?.params as Props)?.type ?? ''}`,
title: `${services.t.do('example.title')} ${(props?.route?.params as Params)?.type ?? ''}`,
});

0 comments on commit 7accb37

Please sign in to comment.