Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rn-portal-confirm

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rn-portal-confirm

test

  • 0.1.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Native Confirm

Features

  • implement ReactDom.Portal in React Native.
  • multiple portalhost support.
  • programmatically create components and support refresh.
  • position configurable for dynamic components, e.g. center,bottom,top,auto.
  • support for Confirm Dialog out of box.

Example Screenshot

Architechter_Graphic

Installation And Usage

  • install package
npm install rn-portal-confirm --save
  • Add the PortalProvider in the Entry Component, e.g App.
// assume we are in render function of App, Wrapper children under PortalProvider
<PortalProvider>
xxx
</PortalProvider>

  • Add any PortalHost if needed, elements will be ported under this host. By default, we will create a root Portalhost in the PortalProvider. so you can skip this step, if single portalHost can match your requirement.
<PortalHost name='xxxuniquename'></PortalHost>

Example and API

for detail examples, please refer to the example in the source code. Bellow give two classic usage.

Confirm Dialog usage

call API to create confirm dialog before your process

import {useConfirm} from 'rn-portal-confirm';
const confirm = useConfirm();
confirm({
      message: 'Are you sure to do something?',
      ok: (closeMe)=>{dosomething();closeMe();},
      cancel: (closeMe) => closeMe(),
    });

Params

  • useConfirm(portalHost?: string):confirm
ParameterDescriptiondefaultValue
portalHostthe PortalHost Name in which the elements will be portedby default it is the rootPortal
  • confirm(param:ConfirmProps):[close,update];
export interface ConfirmProps {
  title?: ReactElement | string;
  message?: ReactElement | string;
  okText?: ReactElement | string;
  cancelText?: ReactElement | string;
  ok?: (closeMe: () => void) => void,
  cancel?: (closeMe: () => void) => void,
  dimissOnBackdropClick?: boolean;
  hideCancel?: boolean;
  Dialog?: (typeof React.Component<any>) | (React.FC<any>);
}

close:()=>void;
update:(props:ConfirmProps)=>void;

Here is the some definition of the ConfirmProps

ParameterTypeDescriptiondefaultValue
dimissOnBackdropClickbooleanindicate if the Confirm Dialog will be closed if drawback is clickedfalse
hideCancelbooleanindicate if the cancel button is hiddenfalse
DialogReact Componentinidcate which Modal will be used to Modal the Confirm,we provide one similar like the Dialog Component in React-native-elements,you can change it if it can't match your requirementsunderfined
titlestirng or ReactElementthe title of the confirm Dialog, you can provide a View if the default style can't match your requirementsnull
messagestring or ReactElementthe message of the confirm Dialognull
okTextstring or ReactElementtext of Ok BtnYes
cancelTextstring or ReactElementtext of Cancel BtnNo
okfunctioncallback function if ok button is clickedunderfined
cancelfunctioncallback function if cancel button is clickedunderfined

Open Dynamic Components

we use useComponent to open a custom component in the Modal.

import { useComponent } from 'rn-portal-confirm';
const open = useComponent();

let componentRef: ReturnType<typeof open>;
const confirm = () => {
  componentRef?.close();
}
const component = (
      <View>
        <Text>Hello, I am a custom Component</Text>
        <View style={{ marginTop: 20 }}>
          <Button title='Close Me' onPress={confirm}></Button>
        </View>
      </View>
    );

componentRef = open(component);

Architechter Graphics

Architechter_Graphic

Support this package

If you like this package, consider giving it a github star ⭐

Also, PR's are welcome!

Keywords

FAQs

Package last updated on 07 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc