mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor RCTActionSheetManager to use RCTConvertVecToArray and RCTConvertOptionalVecToArray
Summary: Previously, I introduced methods to convert `facebook::react::LazyVector<T>` to `NSArray*`, but I realized that there are already methods available in `RCTConvertHelpers` that do this for us. So, I'm switching over to using those methods instead. Reviewed By: fkgozali Differential Revision: D17716914 fbshipit-source-id: e1ef7636e36b594bc558d7025573082bd2bccab9
This commit is contained in:
committed by
Facebook Github Bot
parent
48653a2a63
commit
de20eb7e11
@@ -14,6 +14,7 @@
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
|
||||
#import "CoreModulesPlugins.h"
|
||||
|
||||
@@ -55,26 +56,6 @@ RCT_EXPORT_MODULE()
|
||||
[parentViewController presentViewController:alertController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
NSArray<NSString *> *convertLazyVectorToNSArray(facebook::react::LazyVector<NSString *> vec) {
|
||||
NSMutableArray<NSString *> *array = [NSMutableArray new];
|
||||
for (auto it = vec.begin(); it != vec.end(); it++) {
|
||||
[array addObject:*it];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
NSArray<NSNumber *> *convertLazyVectorToNSArray(facebook::react::LazyVector<double> vec) {
|
||||
NSMutableArray<NSNumber *> *array = [NSMutableArray new];
|
||||
for (auto it = vec.begin(); it != vec.end(); it++) {
|
||||
[array addObject:@(*it)];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
RCT_EXPORT_METHOD(showActionSheetWithOptions:(JS::NativeActionSheetManager::SpecShowActionSheetWithOptionsOptions &)options
|
||||
callback:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
@@ -89,11 +70,11 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions:(JS::NativeActionSheetManager::Spec
|
||||
|
||||
NSString *title = options.title();
|
||||
NSString *message = options.message();
|
||||
NSArray<NSString *> *buttons = [RCTConvert NSStringArray:options.options() ? convertLazyVectorToNSArray(*options.options()) : nil];
|
||||
NSArray<NSString *> *buttons = RCTConvertOptionalVecToArray(options.options(), ^id(NSString *element) { return element; });
|
||||
NSInteger cancelButtonIndex = options.cancelButtonIndex() ? [RCTConvert NSInteger:@(*options.cancelButtonIndex())] : -1;
|
||||
NSArray<NSNumber *> *destructiveButtonIndices;
|
||||
if (options.destructiveButtonIndices()) {
|
||||
destructiveButtonIndices = [RCTConvert NSArray:convertLazyVectorToNSArray(*options.destructiveButtonIndices())];
|
||||
destructiveButtonIndices = RCTConvertVecToArray(*options.destructiveButtonIndices(), ^id(double element) { return @(element); });
|
||||
} else {
|
||||
NSNumber *destructiveButtonIndex = @-1;
|
||||
destructiveButtonIndices = @[destructiveButtonIndex];
|
||||
@@ -193,7 +174,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(JS::NativeActionSheetManager:
|
||||
[shareController setValue:subject forKey:@"subject"];
|
||||
}
|
||||
|
||||
NSArray *excludedActivityTypes = [RCTConvert NSStringArray:options.excludedActivityTypes() ? convertLazyVectorToNSArray(*options.excludedActivityTypes()) : nil];
|
||||
NSArray *excludedActivityTypes = RCTConvertOptionalVecToArray(options.excludedActivityTypes(), ^id(NSString *element) { return element; });
|
||||
if (excludedActivityTypes) {
|
||||
shareController.excludedActivityTypes = excludedActivityTypes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user