Skip to content

Commit 86bb656

Browse files
christopherdrofacebook-github-bot-7
authored andcommitted
Add tintColor for buttons.
Summary: Closes facebook#3374 Closes facebook#4590 Reviewed By: javache Differential Revision: D2729616 Pulled By: mkonicek fb-gh-sync-id: 4a3b6de10a09cad73dbd9d5d552adc3f6ba054e0
1 parent f8be783 commit 86bb656

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

Examples/UIExplorer/ActionSheetIOSExample.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var BUTTONS = [
2727
'Option 0',
2828
'Option 1',
2929
'Option 2',
30-
'Destruct',
30+
'Delete',
3131
'Cancel',
3232
];
3333
var DESTRUCTIVE_INDEX = 3;
@@ -65,6 +65,40 @@ var ActionSheetExample = React.createClass({
6565
}
6666
});
6767

68+
var ActionSheetTintExample = React.createClass({
69+
getInitialState() {
70+
return {
71+
clicked: 'none',
72+
};
73+
},
74+
75+
render() {
76+
return (
77+
<View>
78+
<Text onPress={this.showActionSheet} style={style.button}>
79+
Click to show the ActionSheet
80+
</Text>
81+
<Text>
82+
Clicked button: {this.state.clicked}
83+
</Text>
84+
</View>
85+
);
86+
},
87+
88+
showActionSheet() {
89+
ActionSheetIOS.showActionSheetWithOptions({
90+
options: BUTTONS,
91+
cancelButtonIndex: CANCEL_INDEX,
92+
destructiveButtonIndex: DESTRUCTIVE_INDEX,
93+
tintColor: 'green',
94+
},
95+
(buttonIndex) => {
96+
this.setState({ clicked: BUTTONS[buttonIndex] });
97+
});
98+
}
99+
});
100+
101+
68102
var ShareActionSheetExample = React.createClass({
69103
getInitialState() {
70104
return {
@@ -123,6 +157,10 @@ exports.examples = [
123157
title: 'Show Action Sheet',
124158
render(): ReactElement { return <ActionSheetExample />; }
125159
},
160+
{
161+
title: 'Show Action Sheet with tinted buttons',
162+
render(): ReactElement { return <ActionSheetTintExample />; }
163+
},
126164
{
127165
title: 'Show Share Action Sheet',
128166
render(): ReactElement { return <ShareActionSheetExample />; }

Libraries/ActionSheetIOS/ActionSheetIOS.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
var RCTActionSheetManager = require('NativeModules').ActionSheetManager;
1515

1616
var invariant = require('invariant');
17+
var processColor = require('processColor');
1718

1819
var ActionSheetIOS = {
1920
showActionSheetWithOptions(options: Object, callback: Function) {
@@ -26,7 +27,7 @@ var ActionSheetIOS = {
2627
'Must provide a valid callback'
2728
);
2829
RCTActionSheetManager.showActionSheetWithOptions(
29-
options,
30+
{...options, tintColor: processColor(options.tintColor)},
3031
callback
3132
);
3233
},
@@ -49,7 +50,7 @@ var ActionSheetIOS = {
4950
'Must provide a valid successCallback'
5051
);
5152
RCTActionSheetManager.showShareActionSheetWithOptions(
52-
options,
53+
{...options, tintColor: processColor(options.tintColor)},
5354
failureCallback,
5455
successCallback
5556
);

Libraries/ActionSheetIOS/RCTActionSheetManager.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#import "RCTUIManager.h"
1717

1818
@interface RCTActionSheetManager () <UIActionSheetDelegate>
19-
2019
@end
2120

2221
@implementation RCTActionSheetManager
@@ -139,6 +138,8 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
139138
alertController.popoverPresentationController.permittedArrowDirections = 0;
140139
}
141140
[controller presentViewController:alertController animated:YES completion:nil];
141+
142+
alertController.view.tintColor = [RCTConvert UIColor:options[@"tintColor"]];
142143
}
143144
}
144145

@@ -210,6 +211,8 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
210211
}
211212

212213
[controller presentViewController:shareController animated:YES completion:nil];
214+
215+
shareController.view.tintColor = [RCTConvert UIColor:options[@"tintColor"]];
213216
}
214217

215218
#pragma mark UIActionSheetDelegate Methods

0 commit comments

Comments
 (0)