├── .gitignore ├── .npmignore ├── README.md ├── ReactNativeStatusBarAlertExample ├── .babelrc ├── .flowconfig ├── .gitignore ├── .watchmanconfig ├── App.js ├── App.test.js ├── README.md ├── app.json ├── package.json └── yarn.lock ├── index.js ├── package.json └── screenshots ├── react-native-statusbar-alert-press.mov.gif ├── react-native-statusbar-alert-pulse.mov.gif └── react-native-statusbar-alert.mov.gif /.gitignore: -------------------------------------------------------------------------------- 1 | ReactNativeStatusBarAlertExample/node_modules 2 | ReactNativeStatusBarAlertExample/.expo/** 3 | ReactNativeStatusBarAlertExample/npm-debug.* 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | screenshots 2 | ReactNativeStatusBarAlertExample 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native Statusbar Alert 2 | 3 | A status bar alert (e.g. in-call, recording, navigating) for React Native 4 | 5 | ## Install 6 | 7 | `npm install react-native-statusbar-alert --save` or `yarn add react-native-statusbar-alert` 8 | 9 | ## Usage 10 | 11 | ### Basic 12 | 13 | ```js 14 | 20 | ``` 21 | 22 | ![basic](screenshots/react-native-statusbar-alert.mov.gif) 23 | 24 | ### Pulse 25 | 26 | ```js 27 | 34 | ``` 35 | 36 | ![pulse](screenshots/react-native-statusbar-alert-pulse.mov.gif) 37 | 38 | ### Press 39 | 40 | ```js 41 | this.navigator.push({id: 'SilentAlert'})} 47 | /> 48 | ``` 49 | 50 | ![press](screenshots/react-native-statusbar-alert-press.mov.gif) 51 | 52 | ### Children 53 | 54 | ```js 55 | 62 | 68 | 69 | ``` 70 | 71 | ## Props 72 | 73 | | Name | Description | Required | Type | Default 74 | | :------------- | :------------------------------ | :---------- | :------------------------ | :------ 75 | | visible | `true` to show, `false` to hide | true | bool | `false` 76 | | message | message to display in alert | true | string | `''` 77 | | onPress | callback on press event | false | func | `null` 78 | | pulse | animate the text or background | false | enum('text','background') | `false` 79 | | backgroundColor | background color | false | [color][1] | `'#3DD84C'` 80 | | highlightColor | color on press and pulse | false | [color][1] | `darken(this.props.backgroundColor, 0.9)` 81 | | color | text color | false | [color][1] | `'white'` 82 | | height | height of children container | false | int | 20 83 | | statusbarHeight | [custom status bar height][2] | false | int | 20 84 | | style | styles for children container | false | [style object][3] | `{}` 85 | 86 | [1]: https://facebook.github.io/react-native/docs/colors.html "React Native Colors" 87 | [2]: https://github.com/brentvatne/react-native-status-bar-size "react-native-status-bar-size" 88 | [3]: https://facebook.github.io/react-native/docs/style.html "React Native Style" 89 | 90 | ## Usage with react-navigation 91 | 92 | Create a navigation element using reat-navigation: 93 | 94 | ```js 95 | import { StackNavigator } from 'react-navigation'; 96 | ``` 97 | 98 | ```js 99 | const NavigationStack = StackNavigator({ 100 | Home: { 101 | screen: HomeScreen 102 | }, 103 | Child: { 104 | screen: ChildScreen 105 | } 106 | }); 107 | ``` 108 | 109 | Render `StatusBarAlert` adjacent with `StatusBar` and `NavigationStack`: 110 | 111 | ```js 112 | 113 | 114 | 119 | 120 | 121 | ``` 122 | 123 | See the [ReactNativeStatusBarAlert](/ReactNativeStatusBarAlert) directory for a complete example. 124 | 125 | ## Alert stack example 126 | 127 | Much like a route stack, you can keep an alert stack as an array of alert objects in your component's state. The StatusBarAlert will render the first alert in the stack, so that as new alerts are pushed into the stack, it will render the most recent alert. If an alert is popped from the stack, StatusBarAlert will render any remaining alerts and when the stack is empty, StatusBarAlert will hide itself. Additionally, the object spread operator (`{...this.state.alerts[0]}`) allows you to declare the default props for alerts in `render()` (e.g. `backgroundColor="#3CC29E"`) and override those props in the alert object (e.g. `backgroundColor="#FF6245"`). 128 | 129 | ```js 130 | render() { 131 | return ( 132 | 133 | 0} 137 | {...this.state.alerts[0]} 138 | /> 139 | 147 | } 148 | /> 149 | 150 | ) 151 | } 152 | showSilentAlert() { 153 | this.setState({ 154 | alerts: [{ 155 | message: 'Silent Switch ON', 156 | onPress: () => this.navigator.push({id: 'SilentAlert'}), 157 | backgroundColor="#FF6245" 158 | }, ...this.state.alerts] 159 | }) 160 | } 161 | hideSilentAlert() { 162 | this.setState({ 163 | alerts: this.state.alerts.filter(alert => alert.message !== 'Silent Switch ON') 164 | }) 165 | } 166 | ``` 167 | 168 | ## Example app 169 | 170 | See the [ReactNativeStatusBarAlertExample](https://github.com/gnestor/react-native-statusbar-alert/tree/master/ReactNativeStatusBarAlertExample) directory for an example React Native app using react-native-statusbar-alert. 171 | -------------------------------------------------------------------------------- /ReactNativeStatusBarAlertExample/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["babel-preset-expo"], 3 | "env": { 4 | "development": { 5 | "plugins": ["transform-react-jsx-source"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ReactNativeStatusBarAlertExample/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | .*/Libraries/react-native/ReactNative.js 16 | 17 | ; Additional create-react-native-app ignores 18 | 19 | ; Ignore duplicate module providers 20 | .*/node_modules/fbemitter/lib/* 21 | 22 | ; Ignore misbehaving dev-dependencies 23 | .*/node_modules/xdl/build/* 24 | .*/node_modules/reqwest/tests/* 25 | 26 | ; Ignore missing expo-sdk dependencies (temporarily) 27 | ; https://github.com/expo/expo/issues/162 28 | .*/node_modules/expo/src/* 29 | 30 | ; Ignore react-native-fbads dependency of the expo sdk 31 | .*/node_modules/react-native-fbads/* 32 | 33 | [include] 34 | 35 | [libs] 36 | node_modules/react-native/Libraries/react-native/react-native-interface.js 37 | node_modules/react-native/flow 38 | flow/ 39 | 40 | [options] 41 | module.system=haste 42 | 43 | emoji=true 44 | 45 | experimental.strict_type_args=true 46 | 47 | munge_underscores=true 48 | 49 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 50 | 51 | suppress_type=$FlowIssue 52 | suppress_type=$FlowFixMe 53 | suppress_type=$FixMe 54 | 55 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 56 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 57 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 58 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 59 | 60 | unsafe.enable_getters_and_setters=true 61 | 62 | [version] 63 | ^0.49.1 64 | -------------------------------------------------------------------------------- /ReactNativeStatusBarAlertExample/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .expo/ 3 | npm-debug.* 4 | -------------------------------------------------------------------------------- /ReactNativeStatusBarAlertExample/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /ReactNativeStatusBarAlertExample/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Button, 4 | Image, 5 | StatusBar, 6 | StyleSheet, 7 | Text, 8 | View 9 | } from 'react-native'; 10 | import { StackNavigator } from 'react-navigation'; 11 | import PropTypes from 'prop-types'; 12 | import StatusBarAlert from 'react-native-statusbar-alert'; 13 | 14 | export class HomeScreen extends React.Component { 15 | static navigationOptions = { 16 | title: 'Home View' 17 | }; 18 | static contextTypes = { 19 | toggleAlert: PropTypes.func 20 | }; 21 | render() { 22 | const { navigate } = this.props.navigation; 23 | return ( 24 | 25 | react-native-statusbar-alert + react-navigation example app 26 |