Skip to content

[ActionSheetIOS] Add tintColor for buttons. #4590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Libraries/ActionSheetIOS/ActionSheetIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var RCTActionSheetManager = require('NativeModules').ActionSheetManager;

var invariant = require('invariant');
var processColor = require('processColor');

var ActionSheetIOS = {
showActionSheetWithOptions(options: Object, callback: Function) {
Expand All @@ -25,6 +26,9 @@ var ActionSheetIOS = {
typeof callback === 'function',
'Must provide a valid callback'
);

options.tintColor = processColor(options.tintColor);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull all this code out into a helper function so it can be shared with showShareActionSheetWithOptions

RCTActionSheetManager.showActionSheetWithOptions(
options,
callback
Expand All @@ -48,6 +52,9 @@ var ActionSheetIOS = {
typeof successCallback === 'function',
'Must provide a valid successCallback'
);

options.tintColor = processColor(options.tintColor);

RCTActionSheetManager.showShareActionSheetWithOptions(
options,
failureCallback,
Expand Down
9 changes: 8 additions & 1 deletion Libraries/ActionSheetIOS/RCTActionSheetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
NSArray<NSString *> *buttons = [RCTConvert NSStringArray:options[@"options"]];
NSInteger destructiveButtonIndex = options[@"destructiveButtonIndex"] ? [RCTConvert NSInteger:options[@"destructiveButtonIndex"]] : -1;
NSInteger cancelButtonIndex = options[@"cancelButtonIndex"] ? [RCTConvert NSInteger:options[@"cancelButtonIndex"]] : -1;

UIColor *tintColor = [RCTConvert UIColor:options[@"tintColor"]];

UIViewController *controller = RCTKeyWindow().rootViewController;
if (controller == nil) {
RCTLogError(@"Tried to display action sheet but there is no application window. options: %@", options);
Expand Down Expand Up @@ -139,6 +140,8 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
alertController.popoverPresentationController.permittedArrowDirections = 0;
}
[controller presentViewController:alertController animated:YES completion:nil];

alertController.view.tintColor = tintColor;
}
}

Expand Down Expand Up @@ -176,6 +179,8 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
if (excludedActivityTypes) {
shareController.excludedActivityTypes = excludedActivityTypes;
}

UIColor *tintColor = [RCTConvert UIColor:options[@"tintColor"]];

UIViewController *controller = RCTKeyWindow().rootViewController;

Expand Down Expand Up @@ -210,6 +215,8 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
}

[controller presentViewController:shareController animated:YES completion:nil];

shareController.view.tintColor = tintColor;
}

#pragma mark UIActionSheetDelegate Methods
Expand Down