1.0.2 • Published 5 years ago

react-native-in-app-popup-notification v1.0.2

Weekly downloads
19
License
MIT
Repository
-
Last release
5 years ago

react-native-in-app-popup-notification

Purpose

This React Native library allows you to create a small popup notification on top of the screen that is overlayed above all other views. Works with both iOS and Android.

Install

$ npm install react-native-in-app-popup-notification --save

Usage

Inside a component:

	...
	render() {
		return(
			<View style={styles.container}>
				...
				<InAppPopupNotification {...this.popupProps} ref={(popup) => this.popup = popup}/>
			</View>
		);
	}

	// Called somewhere, you choose where
	showPopup = () => {
		if (this.refs.popup) {
			this.refs.popup.displayPopup({
				title: 'Oh?',
				message: 'A wild popup appeared!',
			});
		}
	};

	popupProps = {
		// see below for provided props
		...
	};
	...

Make sure the InAppPopupNotification is the last component in your parent view.

Props

Note that none of these props are required.

Prop NameTypeDescriptionDefault
titleStringThe popup view's title.'Congratulations!'
messageStringThe popup view's message.'You got Notified!'
iconPathStringAn icon present within your hybrid app's resource. See herehttps://facebook.github.io/react-native/docs/images#images-from-hybrid-app-s-resources) for more information.null
backgroundColorStringThe content's background color.'#FFF'
titleColorStringThe title's text color.'#000'
titleFontStringThe title's font.'system font'
messageColorStringThe message's text color.'#000'
messageFontStringThe message's font.'system font'
opacitynumberA value, 0-1 (inclusive), that controls the popup's opacity.1
heightnumberThe popup's height.getStatusBarHeight(false) + 100
inOutDurationnumberThe duration of the popup's appear and disappear animations, in ms.500
showDurationnumberHow long the popup is showed to the user, in ms.5000
popupWasClickedfunctionExecutes when the popup registers a user tap.() => { }
popupDidAppearfunctionExecutes when the popup appears on the screen and after its in animation.() => { }
popupDidDisappearfunctionExecutes when the popup is no longer displayed on the screen.() => { }
popupWillAppearfunctionExecutes when the popup recieves the command to appear on the screen, before the inward animation.() => { }
popupWillDisappearfunctionExecutes when the popup recieves the command to leave the screen, after the outward animation.() => { }
useNativeDriverbooleanWhether or not to use the native driver for animations. See here for details.false

Available methods

There are three methods you can use to to control when your popup displays.

displayPopup(parameters) takes in a map with message and title key-value pairs. It displays the notification. Example:

	...
	popup.displayPopup({
		title: 'A reference of some sort',
		message: '===To be continued==>',
	});
	...

Note that only one popup can be displayed at a time. Repeated calls are ignored, and a warning is triggered within the console.

dismissPopup(callback) takes in a callback function. If the popup is currently visible, it dismisses it immediately and then executes the callback when the popup has completed its outward animation. If the popup is not visible, it returns a warning. Example:

	...
	popup.dismissPopup(() => {
		Alert.alert('Popup is rip in kill, press F to pay resepcts');
	});
	...

isVisible() simply returns whether or not the popup is visible. Example:

	...
	if (this.popup.isVisible()) {
		this.popup.dismissPopup();
	}
	...

Libraries

This project used the following libraries. Go check them out! react-native-status-bar-height react-native-timer

License

Licensed under the MIT license. See the License file for more information.