Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Created April 18, 2021 05:53
Show Gist options
  • Save qkreltms/96450c79bb94da53282eb098eed7a756 to your computer and use it in GitHub Desktop.
Save qkreltms/96450c79bb94da53282eb098eed7a756 to your computer and use it in GitHub Desktop.
// 모바일 앱이지만, 웹과 비슷합니다.
//우리의 modal 컴포넌트가 있는 곳입니다. 웹에 비유하면 App.jsx 위치쯤이라 보면 됩니다.

function RootNavigator(): ReactElement {
  const navigation = useNavigation();
  const { state } = useProfileContext();
  const modalEl = useRef(null);
  // 컨텍스트에 modal ref를 주입해줍니다.
  state.modal = modalEl;
  return (
    <View
      style={{
        flex: 1,
        flexDirection: 'column',
      }}
    >
      // ...
      // 우리의 Modal 컴포넌트!
      <ProfileModal
        testID="modal"
        ref={state.modal}
        onChatPressed={(): void => {
          if (state.modal && state.modal.current) {
            state.modal.current.close();
          }
          navigation.navigate('Message');
        }}
      />
    </View>
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment