react-native-safe-area-context#SafeAreaConsumer TypeScript Examples

The following examples show how to use react-native-safe-area-context#SafeAreaConsumer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SafeAreaProviderCompat.tsx    From nlw2-proffy with MIT License 6 votes vote down vote up
export default function SafeAreaProviderCompat({ children }: Props) {
  return (
    <SafeAreaConsumer>
      {(insets) => {
        if (insets) {
          // If we already have insets, don't wrap the stack in another safe area provider
          // This avoids an issue with updates at the cost of potentially incorrect values
          // https://github.com/react-navigation/react-navigation/issues/174
          return children;
        }

        return (
          <SafeAreaProvider initialSafeAreaInsets={initialSafeAreaInsets}>
            {children}
          </SafeAreaProvider>
        );
      }}
    </SafeAreaConsumer>
  );
}
Example #2
Source File: StackView.tsx    From nlw2-proffy with MIT License 5 votes vote down vote up
render() {
    const {
      state,
      navigation,
      keyboardHandlingEnabled,
      mode = 'card',
      headerMode = mode === 'card' && Platform.OS === 'ios'
        ? 'float'
        : 'screen',
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      descriptors: _,
      ...rest
    } = this.props;

    const {
      routes,
      descriptors,
      openingRouteKeys,
      closingRouteKeys,
    } = this.state;

    return (
      <NavigationHelpersContext.Provider value={navigation}>
        <GestureHandlerWrapper style={styles.container}>
          <SafeAreaProviderCompat>
            <SafeAreaConsumer>
              {(insets) => (
                <KeyboardManager enabled={keyboardHandlingEnabled !== false}>
                  {(props) => (
                    <CardStack
                      mode={mode}
                      insets={insets as EdgeInsets}
                      getPreviousRoute={this.getPreviousRoute}
                      getGesturesEnabled={this.getGesturesEnabled}
                      routes={routes}
                      openingRouteKeys={openingRouteKeys}
                      closingRouteKeys={closingRouteKeys}
                      onOpenRoute={this.handleOpenRoute}
                      onCloseRoute={this.handleCloseRoute}
                      onTransitionStart={this.handleTransitionStart}
                      onTransitionEnd={this.handleTransitionEnd}
                      renderHeader={this.renderHeader}
                      renderScene={this.renderScene}
                      headerMode={headerMode}
                      state={state}
                      descriptors={descriptors}
                      onGestureStart={this.handleGestureStart}
                      onGestureEnd={this.handleGestureEnd}
                      onGestureCancel={this.handleGestureCancel}
                      {...rest}
                      {...props}
                    />
                  )}
                </KeyboardManager>
              )}
            </SafeAreaConsumer>
          </SafeAreaProviderCompat>
        </GestureHandlerWrapper>
      </NavigationHelpersContext.Provider>
    );
  }