2.0.1 • Published 8 months ago

@team-devmonster/react-native-router v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@team-devmonster/react-native-router

This is under devmonster's react & react-native union project.

This project is part of the react-module & react-native-module projects, that integrate react & react-native by the devmonster team. react => @team-devmonster/react-router General react-native-modules load map => here; General react-modules load map => here;

Other react-native modules

author: devmonster

We are always looking for investment or assistance. hompage: https://devmonster.co.kr email: aldegad@devmonster.co.kr

items

It was created for use with a layout sense similar to Html.

  • o => Just tag a.
  • o => It is made for compatibility with react-router. It doesn't do anything here.
  • o => This has scrollview & safet
  • o
  • o
  • o => fixed layout here.
  • o => It is similar to nextjs router
  • o => It is Modals. You can do multiple modal open.
  • o => It is Toast Modals. You can use as function.

Getting started

Before use it, see these.

$ npm install @team-devmonster/react-native-tags@latest @team-devmonster/react-native-router@latest

Examples

Easy. Too Easy.

pages/routerEx/index.tsx

import React from "react";
import { useTheme } from "@local_modules/theme";
import { Theme } from "App.theme";
import { Div, Button } from "@local_modules/tags";
import { A, FixedLayout, Header, Layout } from "@local_modules/router";

const RouterEx = () => {

  const { color } = useTheme<Theme>();
  const router = useRouter();

  const [visibleFull, setVisibleFull] = useState(false);
  const [visibleHandle, setVisibleHandle] = useState(false);
  const [visibleCenter, setVisibleCenter] = useState(false);
  const [visibleClear, setVisibleClear] = useState(false);

  return (
    <Layout
      style={{
        backgroundColor: color.backgroundColor,
        flex: 1,
        padding: 18
      }}>
      <Header
        headerLeft={
          <Button onClick={() => router.back()}>
            <ImgPaperAirplane color={color.primary} width={20} height={20}/>
          </Button>
        }
        title="Hello Header"
        headerRight={
          <Button style={{ marginRight: -20 }}>
            setting
          </Button>
      }>
        <P style={{ height: 56, alignItems: 'center', justifyContent: 'center', backgroundColor: color.step100 }}>next line</P>
      </Header>

      <Div style={{ rowGap: 8 }}>
        <A href='/themeEx'>
          <Button color={color.primary}>themeEx</Button>
        </A>
        
        <A href={{
          pathname: '/routerEx/paramEx',
          query: {
            name: 'soohong kim',
            nickname: 'aldegad',
            company: 'devmonster',
            des: 'use A & href',
          }
        }}>
          <Button color={color.danger}>paramEx(A)</Button>
        </A>
        
        <Button
          onClick={() => {
            router.push({
              pathname: '/routerEx/paramEx',
              query: {
                name: 'soohong kim',
                nickname: 'aldegad',
                company: 'devmonster',
                des: 'use useRouter & push'
              }
            })
          }}
          color={color.danger} 
        >paramEx(Router)</Button>
        
        <A href='https://www.google.co.kr'>
          <Button color={color.warning}>google</Button>
        </A>

        <Button 
          onClick={() => {
            setVisibleFull(true);
          }}
          color={color.danger} 
        >open modal fullScreen</Button>

        <Button 
          onClick={() => {
            setVisibleHandle(true);
          }}
          color={color.danger} 
        >open modal handleScreen</Button>

        <Button 
          onClick={() => {
            setVisibleCenter(true);
          }}
          color={color.danger} 
        >open modal center</Button>

        <Button 
          onClick={() => {
            setVisibleClear(true);
          }}
          color={color.danger}
        >open modal clear</Button>

        <Button 
          onClick={() => {
            Toast({ message: '토스트 완성' });
          }}
          color={color.step900}
        >open Toast</Button>
      </Div>

      <Modal 
        visible={visibleFull}
        onRequestClose={() => setVisibleFull(false)}
        type="fullScreen"
      >
        <H1>Modal Fullscreen</H1>
        
        <Button onClick={() => setVisibleFull(false)}>close Modal</Button>
      </Modal>

      <Modal 
        visible={visibleHandle}
        onRequestClose={() => setVisibleHandle(false)}
        type="handleScreen"
      >
        <H1>Modal HandleScreen</H1>
        
        <Button onClick={() => setVisibleHandle(false)}>close Modal</Button>
      </Modal>

      <Modal 
        visible={visibleCenter}
        onRequestClose={() => setVisibleCenter(false)}
        type="center"
      >
        <H1>Modal Center</H1>
        
        <Button onClick={() => setVisibleCenter(false)}>close Modal</Button>
      </Modal>

      <Modal 
        visible={visibleClear}
        onRequestClose={() => setVisibleClear(false)}
        type="clear"
      >
        <H1>Modal Clear</H1>
        
        <Button onClick={() => setVisibleClear(false)}>close Modal</Button>
      </Modal>
    </Layout>
  )
}

export default RouterEx;

pages/routerEx/paramEx.tsx

import React from "react";
import { useTheme } from "@team-devmonster/react-theme";
import { Theme } from "./App.theme";
import { Div, Button, P } from "@team-devmonster/react-native-tags";
import { A, useRouter, RouterProps } from "@team-devmonster/react-native-router";
import { RootStackParamList } from "App.navigation.type";

const ParamEx = () => {
  const { color } = useTheme<Theme>();
  const router = useRouter<RouterProps<RootStackParamList, 'routerEx/paramEx'>>();
  const { query } = router;

  return (
    <Layout
      style={{
        backgroundColor: color.white,
        padding: 18,
        flex: 1
      }}>
      <Header
        style={{
          backgroundColor: color.primary,
          color: 'red'
        }}
        title="Hello Params"
      />
      <P style={{ padding: 8, backgroundColor: color.step300 }}>
        { query.name } / { query.nickname } / { query.company }
      </P>
      <A back={true}>
        <Button color={color.primary}>Back</Button>
      </A>
      <A href="/tagsEx" replace={true}>
        <Button color={color.primary}>replace this page</Button>
      </A>
      <A href="/index" reset={true}>
        <Button color={color.primary}>reset to home</Button>
      </A>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <P>Scrollllll.....</P>
      <FixedLayout>
        <Div style={{ top: 100, left: 20 }}>HEllo</Div>
      </FixedLayout>
      <Footer style={{
        backgroundColor: color.white
      }}>
        <Div style={{
          flexDirection: 'row',
          backgroundColor: 'red'
        }}>
          <Button color={color.primary} style={{ flex: 1 }}>Tab1</Button>
          <Button color={color.primary} style={{ flex: 1 }}>Tab2</Button>
          <Button color={color.primary} style={{ flex: 1 }}>Tab3</Button>
          <Button color={color.primary} style={{ flex: 1 }}>Tab4</Button>
        </Div>
      </Footer>
    </Layout>
  )
}

export default ParamEx;

App.navigation.tsx

import React from "react";
import { LogBox } from "react-native";

import { DarkTheme, DefaultTheme, NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from '@react-navigation/native-stack';

LogBox.ignoreLogs(['new NativeEventEmitter']); // Ignore log notification by message
// LogBox.ignoreAllLogs(); //Ignore all log notifications

import Index from "@pages/index";
import ThemeEx from "@pages/themeEx";
import TagsEx from "@pages/tagsEx";

import { RootStackParamList } from "App.navigation.type";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { useTheme } from "@local_modules/theme";
import { Theme } from "App.theme";
import RouterEx from "@pages/routerEx";
import ParamEx from "@pages/routerEx/paramEx";
import FormEx from "@pages/formEx";
import SwiperEx from "@pages/swiperEx";


export const AppRouterProvider = ({children}: {children:React.ReactNode}) => {
  const { color, colorScheme } = useTheme<Theme>();
  const theme = colorScheme === 'dark' ? DarkTheme : DefaultTheme;
  // SafeAreaProvider & NavigationContainer are needed to out of RouterProvider
  // style & theme is just option. do what you want.
  return (
    <SafeAreaProvider style={{ flex: 1, backgroundColor: color.white }}>
      <NavigationContainer theme={{
        ...theme,
        colors: {
          ...theme.colors
        }
      }}>
        <RouterProvider>
          {children}
        </RouterProvider>
      </NavigationContainer>
    </SafeAreaProvider>
  )
}

const RootStack = createNativeStackNavigator<RootStackParamList>();

const Navigation = () => {

  const { color, colorScheme } = useTheme<Theme>();
  
  return (
    <RootStack.Navigator initialRouteName="index">
      <RootStack.Screen name="index" component={Index}/>
      <RootStack.Screen name="themeEx" component={ThemeEx}/>
      <RootStack.Screen name="tagsEx" component={TagsEx}/>
      <RootStack.Screen name="routerEx" component={RouterEx}/>
      <RootStack.Screen name="routerEx/paramEx" component={ParamEx}/>
      <RootStack.Screen name="formEx" component={FormEx}/>
      <RootStack.Screen name="swiperEx" component={SwiperEx}/>
    </RootStack.Navigator>
  )
}

export default Navigation;

App.navigation.type.tsx

/**
 * Learn more about using TypeScript with React Navigation:
 * https://reactnavigation.org/docs/typescript/
 */
import { NativeStackScreenProps } from '@react-navigation/native-stack';

export type RootStackParamList = {
  'index':undefined,
  'themeEx':undefined,
  'tagsEx':undefined,
  'routerEx':undefined,
  'routerEx/paramEx':{ name:string, nickname:string, company:string },
  'formEx':undefined,
  'swiperEx':undefined
};

export type RootStackScreenProps<Screen extends keyof RootStackParamList> = NativeStackScreenProps<
  RootStackParamList,
  Screen
>;
export type Query<RouteName extends keyof RootStackParamList> = RootStackParamList[RouteName];
2.0.1

8 months ago

2.0.0

8 months ago

1.9.1

9 months ago

1.9.0

9 months ago

1.9.9

8 months ago

1.9.8

8 months ago

1.9.7

8 months ago

1.9.6

8 months ago

1.9.5

9 months ago

1.9.4

9 months ago

1.9.3

9 months ago

1.9.2

9 months ago

1.8.9

9 months ago

1.8.8

9 months ago

1.8.7

9 months ago

1.8.6

9 months ago

1.8.5

9 months ago

1.8.4

11 months ago

1.8.3

11 months ago

1.8.2

11 months ago

1.8.1

11 months ago

1.8.0

11 months ago

1.7.9

11 months ago

1.7.8

11 months ago

1.7.7

11 months ago

1.7.6

11 months ago

1.7.5

1 year ago

1.7.4

1 year ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.9

1 year ago

1.6.8

1 year ago

1.6.7

1 year ago

1.6.6

1 year ago

1.6.4

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.5

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.9

1 year ago

1.5.10

1 year ago

1.5.12

1 year ago

1.5.8

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

1.5.5

1 year ago

1.5.3

1 year ago

1.4.6

1 year ago

1.2.8

1 year ago

1.4.5

1 year ago

1.2.7

1 year ago

1.4.4

1 year ago

1.2.6

1 year ago

1.4.3

1 year ago

1.2.5

1 year ago

1.4.2

1 year ago

1.2.4

1 year ago

1.4.1

1 year ago

1.2.3

1 year ago

1.4.0

1 year ago

1.3.10

1 year ago

1.3.11

1 year ago

1.3.9

1 year ago

1.3.8

1 year ago

1.2.12

1 year ago

1.2.13

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.3.7

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.5.2

1 year ago

1.3.4

1 year ago

1.5.1

1 year ago

1.3.3

1 year ago

1.5.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.4.9

1 year ago

1.4.8

1 year ago

1.4.7

1 year ago

1.2.9

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago