From d075470a91189d1ea4a1325037d9eb767520a058 Mon Sep 17 00:00:00 2001 From: kblny Date: Tue, 29 Mar 2016 11:11:01 +0200 Subject: [PATCH] ## New Features - New property `shouldHideAfterDelay` : Tell the MessageBar whether or not it should hide after a delay defined in the `duration` property. If `false`, the MessageBar remain shown - New property `shouldHideOnTap` : Tell the MessageBar whether or not it should hide or not when the user tap the alert. If `false`, the MessageBar will not hide, but the `onTapped` function is triggered, if defined. In addition, if `false`, the `onHide` function will not be triggered. The property `shouldHideAfterDelay` take precedence over `shouldHideOnTap`. That means if `shouldHideAfterDelay` is `false`, the value of `shouldHideOnTap` is not taken into account, since the MessageBar will not ever be hidden - New property `titleNumberOfLines` : Number of lines of the title. `0` means unlimited - New property `messageNumberOfLines` : Number of lines of the message. `0` means unlimited - New property `titleStyle` : Style of the title - New property `messageStyle` : Style of the message - New property `avatarStyle` : Style of the icon/avatar ## Bug Fixes - When a MessageBar alert is shown it hide the existing one and display a new one, instead of replacing the existing one with its new state (formerly using properties) ## Breaking Changes - Property `type` renamed to `alertType` --- AppTest.js | 202 +++++++----------- CustomChildComponent.js | 7 +- MessageBar.js | 30 +-- MessageBarManager.js | 42 +++- README.md | 121 ++++++----- .../UserInterfaceState.xcuserstate | Bin 17775 -> 19533 bytes package.json | 5 +- 7 files changed, 197 insertions(+), 210 deletions(-) diff --git a/AppTest.js b/AppTest.js index ece95cf..3365831 100644 --- a/AppTest.js +++ b/AppTest.js @@ -26,118 +26,70 @@ class MessageBar extends Component { this.state = { callbackButton: 'Show Alert with Avatar and Callback (Error Type)', - - alertTitle: 'null', - alertMessage: null, - alertIconUrl: null, - alertType: 'info', - alertDuration: null, - alertCallback: null, } } componentDidMount() { // Register the alert located on this master page - MessageBarManager.setCurrentMessageBarAlert(this.refs.alert); + MessageBarManager.registerMessageBar(this.refs.alert); } componentWillUnmount() { // Remove the alert located on this master page from te manager - MessageBarManager.removeCurrentMessageBarAlert(); + MessageBarManager.unregisterMessageBar(); } showSimpleAlertMessage() { // Title or Message is at least Mandatory - // type is Mandatory too, otherwise 'info' (blue color) will picked for you - this.setState({ - alertTitle: null, - alertMessage: "This is a simple alert with a message.", - alertIconUrl: null, + // alertType is not Mandatory, but if no alertType provided, 'info' (blue color) will picked for you + + // Simple show the alert with the manager + MessageBarManager.showCurrentAlert({ + message: "This is a simple alert with a message.", alertType: 'extra', - alertDuration: null, - alertCallback: null, }); - - // Simple show the alert by its reference - // this.refs.alert.showMessageBarAlert(); - - // Or with the manager - MessageBarManager.showCurrentAlert(); } showSimpleAlert() { - // Title or Message is at least Mandatory - // type is Mandatory too, otherwise 'info' (blue color) will picked for you - this.setState({ - alertTitle: "This is a simple alert", - alertMessage: null, - alertIconUrl: null, + // Simple show the alert with the manager + MessageBarManager.showCurrentAlert({ + title: "This is a simple alert", alertType: 'success', - alertDuration: null, - alertCallback: null, }); - - // Simple show the alert by its reference - // this.refs.alert.showMessageBarAlert(); - - // Or with the manager - MessageBarManager.showCurrentAlert(); } showSimpleAlertWithMessage() { - // Title or Message is at least Mandatory - // type is Mandatory too, otherwise 'info' (blue color) will picked for you - this.setState({ - alertTitle: "Caution !", - alertMessage: "This is a simple alert with a title", - alertIconUrl: null, + // Simple show the alert with the manager + MessageBarManager.showCurrentAlert({ + title: "Caution !", + message: "This is a simple alert with a title", alertType: 'warning', - alertDuration: null, - alertCallback: null, }); - - // Simple show the alert by its reference - // this.refs.alert.showMessageBarAlert(); - - // Or with the manager - MessageBarManager.showCurrentAlert(); } showAlertWithAvatar() { - this.setState({ - alertTitle: "John Doe", - alertMessage: "Hello, how are you?", - alertIconUrl: "https://image.freepik.com/free-icon/super-simple-avatar_318-1018.jpg", + // Simple show the alert with the manager + MessageBarManager.showCurrentAlert({ + title: "John Doe", + message: "Hello, how are you?", + avatarUrl: "https://image.freepik.com/free-icon/super-simple-avatar_318-1018.jpg", alertType: 'info', - alertDuration: null, - alertCallback: null, }); - - // Simple show the alert by its reference - // this.refs.alert.showMessageBarAlert(); - - // Or with the manager - MessageBarManager.showCurrentAlert(); } showAlertWithCallback() { - this.setState({ - alertTitle: "This is an alert with a callback function", - alertMessage: "Tap on the alert to execute the callback you passed in parameter", - alertIconUrl: "http://www.icon100.com/up/4250/128/83-circle-error.png", + // Simple show the alert with the manager + MessageBarManager.showCurrentAlert({ + title: "This is an alert with a callback function", + message: "Tap on the alert to execute the callback you passed in parameter", + avatarUrl: "http://www.icon100.com/up/4250/128/83-circle-error.png", alertType: 'error', - alertDuration: 5000, - alertCallback: this.customCallback.bind(this), + duration: 5000, + onTapped: this.customCallback.bind(this), }); - - // Simple show the alert by its reference - // this.refs.alert.showMessageBarAlert(); - - // Or with the manager - MessageBarManager.showCurrentAlert(); } showAlertFromThrowError() { @@ -154,7 +106,7 @@ class MessageBar extends Component { title: "Error", message: error.message, type: 'error', - avatarUrl: null, + messageNumberOfLines: 0, }); } @@ -185,53 +137,59 @@ class MessageBar extends Component { return ( -