React Native Propel Kit

React Native Propel Kit

  • Quick Start
  • Components
  • Github
  • v0.8.6

›Components

Introduction

  • Quick Start

Components

  • ActionSheetProvider
  • BackdropProvider
  • ModalDialog
  • Select
  • DatePicker
  • TimePicker
  • DateTimePicker
  • MonthPicker
  • YearPicker
  • Picker

Recipes

  • Customizing styles

Backdrop Provider

<BackdropProvider /> is a is a Context Provider that enables the usage of a cross-platform backdrop component anywhere in your application.

  • Can be easily re-used by any other component that requires a backdrop

Preview

iOSAndroid

Usage

Required setup

First you need to wrap your application with a <BackdropProvider /> component. You usually want to wrap it as high as possible in your tree so that the backdrop properly covers the whole screen.

// App.tsx

import React, {FunctionComponent} from 'react';
import {BackdropProvider} from 'react-native-propel-kit';

const App: FunctionComponent = () => {
  return (
    <BackdropProvider>
      <RootNavigator />
    </BackdropProvider>
  );
};

export default App;

Usage with context

Then, the easiest way to use the backdrop in a component is to use react useContext hook

// MyComponent.jsx

import React, {FunctionComponent} from 'react';
import {Button} from 'react-native';
import {BackdropContext} from 'react-native-propel-kit';

const MyComponent: FunctionComponent = () => {
  const backdrop = useContext(BackdropContext);
  const handlePress = useCallback(() => {
    backdrop.show();
  }, [backdrop]);
  return <Button onPress={handlePress} title="Show Backdrop" />;
};

export default MyComponent;

Usage with consumer

An alternative way to use the backdrop is to use the <BackdropContext.Consumer /> component as a higher order component providing the backdrop context API.

// MyComponent.jsx

import React, {FunctionComponent} from 'react';
import {Button} from 'react-native';
import {BackdropContext} from 'react-native-propel-kit';

const MyComponent: FunctionComponent = () => {
  return (
    <BackdropContext.Consumer>
      {backdrop => (
        <Button
          onPress={() => {
            backdrop.show();
          }}
          title="Open"
        />
      )}
    </BackdropContext.Consumer>
  );
};

export default MyComponent;

Props

export type Props = {
  backgroundColor?: string;
  children?: ReactNode;
  duration?: number;
  easing?: EasingFunction;
  opacity?: number;
  useNativeDriver?: boolean;
  zIndex?: number;
};

Defaults

export const defaultProps = {
  backgroundColor: 'black',
  duration: 300,
  easing: Easing.inOut(Easing.ease),
  opacity: IOS_OPACITY,
  useNativeDriver: true,
  zIndex: 99
};
Last updated on 9/24/2019
← ActionSheetProviderModalDialog →
  • Preview
  • Usage
    • Required setup
    • Usage with context
    • Usage with consumer
  • Props
    • Defaults
React Native Propel Kit
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2019 Olivier Louvignes