Skip to content

Commit

Permalink
Remove folly import in GenerateModuleObjCpp
Browse files Browse the repository at this point in the history
Summary:
Changelog:

[iOS][Changed]
Replaced folly::Optional with std::optional from C++17 in Objc module generator.

Reviewed By: philIip

Differential Revision: D32367103

fbshipit-source-id: f0d254c4add7d6d2e0bdbceb09a852b4a01ea8c7
  • Loading branch information
Erich Graham authored and facebook-github-bot committed Mar 23, 2022
1 parent d9f8ac2 commit 45e2941
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 156 deletions.
19 changes: 10 additions & 9 deletions Libraries/TypeSafety/RCTConvertHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

#import <optional>

#import <vector>

#import <Foundation/Foundation.h>

#import <FBLazyVector/FBLazyVector.h>
#import <folly/Optional.h>

namespace facebook {
namespace react {
Expand All @@ -35,22 +36,22 @@ NSArray *RCTConvertVecToArray(const ContainerT &vec)
}

template<typename ContainerT>
NSArray *RCTConvertOptionalVecToArray(const folly::Optional<ContainerT> &vec, id (^convertor)(typename ContainerT::value_type element))
NSArray *RCTConvertOptionalVecToArray(const std::optional<ContainerT> &vec, id (^convertor)(typename ContainerT::value_type element))
{
return vec.hasValue() ? RCTConvertVecToArray(vec.value(), convertor) : nil;
return vec.has_value() ? RCTConvertVecToArray(vec.value(), convertor) : nil;
}

template<typename ContainerT>
NSArray *RCTConvertOptionalVecToArray(const folly::Optional<ContainerT> &vec)
NSArray *RCTConvertOptionalVecToArray(const std::optional<ContainerT> &vec)
{
return vec.hasValue() ? RCTConvertVecToArray(vec.value(), ^id(typename ContainerT::value_type element) { return element; }) : nil;
return vec.has_value() ? RCTConvertVecToArray(vec.value(), ^id(typename ContainerT::value_type element) { return element; }) : nil;
}

bool RCTBridgingToBool(id value);
folly::Optional<bool> RCTBridgingToOptionalBool(id value);
std::optional<bool> RCTBridgingToOptionalBool(id value);
NSString *RCTBridgingToString(id value);
NSString *RCTBridgingToOptionalString(id value);
folly::Optional<double> RCTBridgingToOptionalDouble(id value);
std::optional<double> RCTBridgingToOptionalDouble(id value);
double RCTBridgingToDouble(id value);
NSArray *RCTBridgingToArray(id value);

Expand All @@ -64,10 +65,10 @@ facebook::react::LazyVector<T> RCTBridgingToVec(id value, T (^ctor)(id element))
}

template<typename T>
folly::Optional<facebook::react::LazyVector<T>> RCTBridgingToOptionalVec(id value, T (^ctor)(id element))
std::optional<facebook::react::LazyVector<T>> RCTBridgingToOptionalVec(id value, T (^ctor)(id element))
{
if (value == nil || value == (id)kCFNull) {
return folly::none;
return std::nullopt;
} else {
return RCTBridgingToVec(value, ctor);
}
Expand Down
4 changes: 2 additions & 2 deletions Libraries/TypeSafety/RCTConvertHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool RCTBridgingToBool(id value)
return [RCTConvert BOOL:value] ? true : false;
}

folly::Optional<bool> RCTBridgingToOptionalBool(id value)
std::optional<bool> RCTBridgingToOptionalBool(id value)
{
if (!RCTNilIfNull(value)) {
return {};
Expand All @@ -33,7 +33,7 @@ bool RCTBridgingToBool(id value)
}


folly::Optional<double> RCTBridgingToOptionalDouble(id value)
std::optional<double> RCTBridgingToOptionalDouble(id value)
{
if (!RCTNilIfNull(value)) {
return {};
Expand Down
7 changes: 1 addition & 6 deletions Libraries/TypeSafety/RCTTypeSafety.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ else
source[:tag] = "v#{version}"
end

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
folly_version = '2021.06.28.00-v2'

Pod::Spec.new do |s|
s.name = "RCTTypeSafety"
s.version = version
Expand All @@ -27,18 +24,16 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.author = "Facebook, Inc. and its affiliates"
s.platforms = { :ios => "12.4" }
s.compiler_flags = folly_compiler_flags
s.source = source
s.source_files = "**/*.{c,h,m,mm,cpp}"
s.header_dir = "RCTTypeSafety"
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/TypeSafety\" \"$(PODS_ROOT)/RCT-Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/TypeSafety\""
}

s.dependency "FBLazyVector", version
s.dependency "RCT-Folly", folly_version
s.dependency "RCTRequired", version
s.dependency "React-Core", version
end
4 changes: 2 additions & 2 deletions React/CoreModules/RCTAccessibilityManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ - (void)setMultipliers:(NSDictionary<NSString *, NSNumber *> *)multipliers
static void setMultipliers(
NSMutableDictionary<NSString *, NSNumber *> *multipliers,
NSString *key,
folly::Optional<double> optionalDouble)
std::optional<double> optionalDouble)
{
if (optionalDouble.hasValue()) {
if (optionalDouble.has_value()) {
multipliers[key] = @(optionalDouble.value());
}
}
Expand Down
6 changes: 3 additions & 3 deletions React/CoreModules/RCTExceptionsManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ - (void)reportFatal:(NSString *)message stack:(NSArray<NSDictionary *> *)stack e
NSMutableArray<NSDictionary *> *stackArray = [NSMutableArray<NSDictionary *> new];
for (auto frame : data.stack()) {
NSMutableDictionary *frameDict = [NSMutableDictionary new];
if (frame.column().hasValue()) {
if (frame.column().has_value()) {
frameDict[@"column"] = @(frame.column().value());
}
frameDict[@"file"] = frame.file();
if (frame.lineNumber().hasValue()) {
if (frame.lineNumber().has_value()) {
frameDict[@"lineNumber"] = @(frame.lineNumber().value());
}
frameDict[@"methodName"] = frame.methodName();
if (frame.collapse().hasValue()) {
if (frame.collapse().has_value()) {
frameDict[@"collapse"] = @(frame.collapse().value());
}
[stackArray addObject:frameDict];
Expand Down
2 changes: 2 additions & 0 deletions React/CoreModules/RCTPlatform.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#import "CoreModulesPlugins.h"

#import <folly/Optional.h>

using namespace facebook::react;

static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom)
Expand Down
2 changes: 1 addition & 1 deletion React/CoreModules/RCTStatusBarManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
RCTUnsafeExecuteOnMainQueueSync(^{
constants = facebook::react::typedConstants<JS::NativeStatusBarManagerIOS::Constants>({
.HEIGHT = RCTSharedApplication().statusBarFrame.size.height,
.DEFAULT_BACKGROUND_COLOR = folly::none,
.DEFAULT_BACKGROUND_COLOR = std::nullopt,
});
});

Expand Down
Loading

0 comments on commit 45e2941

Please sign in to comment.