From 86bb656e6fa52707b36b94fa04d7bec170badb72 Mon Sep 17 00:00:00 2001 From: Christopher Dro Date: Wed, 9 Dec 2015 05:08:36 -0800 Subject: [PATCH] Add tintColor for buttons. Summary: Closes #3374 Closes https://github.com/facebook/react-native/pull/4590 Reviewed By: javache Differential Revision: D2729616 Pulled By: mkonicek fb-gh-sync-id: 4a3b6de10a09cad73dbd9d5d552adc3f6ba054e0 --- Examples/UIExplorer/ActionSheetIOSExample.js | 40 ++++++++++++++++++- Libraries/ActionSheetIOS/ActionSheetIOS.js | 5 ++- .../ActionSheetIOS/RCTActionSheetManager.m | 5 ++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Examples/UIExplorer/ActionSheetIOSExample.js b/Examples/UIExplorer/ActionSheetIOSExample.js index 1ef41c1ed..ccc86fba4 100644 --- a/Examples/UIExplorer/ActionSheetIOSExample.js +++ b/Examples/UIExplorer/ActionSheetIOSExample.js @@ -27,7 +27,7 @@ var BUTTONS = [ 'Option 0', 'Option 1', 'Option 2', - 'Destruct', + 'Delete', 'Cancel', ]; var DESTRUCTIVE_INDEX = 3; @@ -65,6 +65,40 @@ var ActionSheetExample = React.createClass({ } }); +var ActionSheetTintExample = React.createClass({ + getInitialState() { + return { + clicked: 'none', + }; + }, + + render() { + return ( + + + Click to show the ActionSheet + + + Clicked button: {this.state.clicked} + + + ); + }, + + showActionSheet() { + ActionSheetIOS.showActionSheetWithOptions({ + options: BUTTONS, + cancelButtonIndex: CANCEL_INDEX, + destructiveButtonIndex: DESTRUCTIVE_INDEX, + tintColor: 'green', + }, + (buttonIndex) => { + this.setState({ clicked: BUTTONS[buttonIndex] }); + }); + } +}); + + var ShareActionSheetExample = React.createClass({ getInitialState() { return { @@ -123,6 +157,10 @@ exports.examples = [ title: 'Show Action Sheet', render(): ReactElement { return ; } }, + { + title: 'Show Action Sheet with tinted buttons', + render(): ReactElement { return ; } + }, { title: 'Show Share Action Sheet', render(): ReactElement { return ; } diff --git a/Libraries/ActionSheetIOS/ActionSheetIOS.js b/Libraries/ActionSheetIOS/ActionSheetIOS.js index 155b7d74e..c63618441 100644 --- a/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -14,6 +14,7 @@ var RCTActionSheetManager = require('NativeModules').ActionSheetManager; var invariant = require('invariant'); +var processColor = require('processColor'); var ActionSheetIOS = { showActionSheetWithOptions(options: Object, callback: Function) { @@ -26,7 +27,7 @@ var ActionSheetIOS = { 'Must provide a valid callback' ); RCTActionSheetManager.showActionSheetWithOptions( - options, + {...options, tintColor: processColor(options.tintColor)}, callback ); }, @@ -49,7 +50,7 @@ var ActionSheetIOS = { 'Must provide a valid successCallback' ); RCTActionSheetManager.showShareActionSheetWithOptions( - options, + {...options, tintColor: processColor(options.tintColor)}, failureCallback, successCallback ); diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index 245493b0c..6d568a0a4 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -16,7 +16,6 @@ #import "RCTUIManager.h" @interface RCTActionSheetManager () - @end @implementation RCTActionSheetManager @@ -139,6 +138,8 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions:(NSDictionary *)options alertController.popoverPresentationController.permittedArrowDirections = 0; } [controller presentViewController:alertController animated:YES completion:nil]; + + alertController.view.tintColor = [RCTConvert UIColor:options[@"tintColor"]]; } } @@ -210,6 +211,8 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options } [controller presentViewController:shareController animated:YES completion:nil]; + + shareController.view.tintColor = [RCTConvert UIColor:options[@"tintColor"]]; } #pragma mark UIActionSheetDelegate Methods