Skip to content

Commit

Permalink
hook up useNativeViewConfigsInBridgelessMode feature flag (#47265)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #47265

Changelog: [iOS][Breaking]

This was originally landed before as part of the effort to coalesce configurations with the feature flag infra, but got reverted due to a build issue. I'm pretty sure it was just because the legacy configuration methods were not cleaned up from the header (RCTConstants.h). I fixed that here.

Reviewed By: javache

Differential Revision: D65092536

fbshipit-source-id: 5012ba54b0314c487f2ef488c2eb30a3c4133cb5
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 29, 2024
1 parent 0fc2e95 commit 6fc500e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 45 deletions.
21 changes: 13 additions & 8 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#endif
#import <react/nativemodule/defaults/DefaultTurboModules.h>

using namespace facebook::react;

@interface RCTAppDelegate () <RCTComponentViewFactoryComponentProvider, RCTHostDelegate>
@end

Expand Down Expand Up @@ -224,15 +226,14 @@ - (Class)getModuleClassFromName:(const char *)name
#endif
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
- (std::shared_ptr<TurboModule>)getTurboModule:(const std::string &)name
jsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
{
return facebook::react::DefaultTurboModules::getTurboModule(name, jsInvoker);
return DefaultTurboModules::getTurboModule(name, jsInvoker);
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
initParams:
(const facebook::react::ObjCTurboModule::InitParams &)params
- (std::shared_ptr<TurboModule>)getTurboModule:(const std::string &)name
initParams:(const ObjCTurboModule::InitParams &)params
{
return nullptr;
}
Expand Down Expand Up @@ -306,7 +307,7 @@ - (RCTRootViewFactory *)createRCTRootViewFactory

#pragma mark - Feature Flags

class RCTAppDelegateBridgelessFeatureFlags : public facebook::react::ReactNativeFeatureFlagsDefaults {
class RCTAppDelegateBridgelessFeatureFlags : public ReactNativeFeatureFlagsDefaults {
public:
bool enableBridgelessArchitecture() override
{
Expand All @@ -320,12 +321,16 @@ bool useTurboModules() override
{
return true;
}
bool useNativeViewConfigsInBridgelessMode() override
{
return true;
}
};

- (void)_setUpFeatureFlags
{
if ([self bridgelessEnabled]) {
facebook::react::ReactNativeFeatureFlags::override(std::make_unique<RCTAppDelegateBridgelessFeatureFlags>());
ReactNativeFeatureFlags::override(std::make_unique<RCTAppDelegateBridgelessFeatureFlags>());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,9 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions
{
NSDictionary *initProps = updateInitialProps(initialProperties, self->_configuration.fabricEnabled);

if (self->_configuration.bridgelessEnabled) {
// Enable native view config interop only if both bridgeless mode and Fabric is enabled.
RCTSetUseNativeViewConfigsInBridgelessMode(self->_configuration.fabricEnabled);
NSDictionary *initProps = updateInitialProps(initialProperties, _configuration.fabricEnabled);

if (_configuration.bridgelessEnabled) {
// Enable TurboModule interop by default in Bridgeless mode
RCTEnableTurboModuleInterop(YES);
RCTEnableTurboModuleInteropBridgeProxy(YES);
Expand All @@ -190,8 +187,8 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
[self createBridgeAdapterIfNeeded];

UIView *rootView;
if (self->_configuration.createRootViewWithBridge != nil) {
rootView = self->_configuration.createRootViewWithBridge(self.bridge, moduleName, initProps);
if (_configuration.createRootViewWithBridge != nil) {
rootView = _configuration.createRootViewWithBridge(self.bridge, moduleName, initProps);
} else {
rootView = [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps];
}
Expand Down
6 changes: 0 additions & 6 deletions packages/react-native/React/Base/RCTConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,3 @@ RCT_EXTERN void RCTSetDispatchW3CPointerEvents(BOOL value);
*/
RCT_EXTERN int RCTGetMemoryPressureUnloadLevel(void);
RCT_EXTERN void RCTSetMemoryPressureUnloadLevel(int value);

/*
* Use native view configs in bridgeless mode
*/
RCT_EXTERN BOOL RCTGetUseNativeViewConfigsInBridgelessMode(void);
RCT_EXTERN void RCTSetUseNativeViewConfigsInBridgelessMode(BOOL value);
15 changes: 0 additions & 15 deletions packages/react-native/React/Base/RCTConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,3 @@ void RCTSetMemoryPressureUnloadLevel(int value)
{
RCTMemoryPressureUnloadLevel = value;
}

/*
* Use native view configs in bridgeless mode
*/
static BOOL RCTUseNativeViewConfigsInBridgelessMode = NO;

BOOL RCTGetUseNativeViewConfigsInBridgelessMode(void)
{
return RCTUseNativeViewConfigsInBridgelessMode;
}

void RCTSetUseNativeViewConfigsInBridgelessMode(BOOL value)
{
RCTUseNativeViewConfigsInBridgelessMode = value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <AVFoundation/AVFoundation.h>
#import <React/RCTSurfacePresenterStub.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>

#import "RCTAssert.h"
#import "RCTBridge+Private.h"
Expand Down Expand Up @@ -1154,10 +1155,10 @@ - (void)flushUIBlocksWithCompletion:(void (^)(void))completion
return;
}

__weak typeof(self) weakSelf = self;
__weak __typeof(self) weakSelf = self;

void (^mountingBlock)(void) = ^{
typeof(self) strongSelf = weakSelf;
__typeof(self) strongSelf = weakSelf;

@try {
for (RCTViewManagerUIBlock block in previousPendingUIBlocks) {
Expand Down Expand Up @@ -1438,7 +1439,7 @@ static void RCTMeasureLayout(RCTShadowView *view, RCTShadowView *ancestor, RCTRe
// lazifyViewManagerConfig function in JS. This fuction uses NativeModules global object that is not available in the
// New Architecture. To make native view configs work in the New Architecture we will populate these properties in
// native.
if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
if (facebook::react::ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) {
moduleConstants[@"Commands"] = viewConfig[@"Commands"];
moduleConstants[@"Constants"] = viewConfig[@"Constants"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "RCTComponentData.h"

#import <objc/message.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>

#import "RCTBridge.h"
#import "RCTBridgeModule.h"
Expand Down Expand Up @@ -288,9 +289,9 @@ - (RCTPropBlock)createPropBlock:(NSString *)name isShadowView:(BOOL)isShadowView
case _value: { \
__block BOOL setDefaultValue = NO; \
__block _type defaultValue; \
_type (*convert)(id, SEL, id) = (typeof(convert))objc_msgSend; \
_type (*get)(id, SEL) = (typeof(get))objc_msgSend; \
void (*set)(id, SEL, _type) = (typeof(set))objc_msgSend; \
_type (*convert)(id, SEL, id) = (__typeof(convert))objc_msgSend; \
_type (*get)(id, SEL) = (__typeof(get))objc_msgSend; \
void (*set)(id, SEL, _type) = (__typeof(set))objc_msgSend; \
setterBlock = ^(id target, id json) { \
if (json) { \
if (!setDefaultValue && target) { \
Expand Down Expand Up @@ -522,7 +523,7 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forView:(id<RCTComponent>
@"baseModuleName" : superClass == [NSObject class] ? (id)kCFNull : RCTViewManagerModuleNameForClass(superClass),
}];

if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
if (facebook::react::ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) {
result[@"Commands"] = [self commandsForViewMangerClass:managerClass methods:methods methodCount:count];
result[@"Constants"] = [self constantsForViewMangerClass:managerClass];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ folly_version = folly_config[:version]
folly_dep_name = folly_config[:dep_name]

boost_config = get_boost_config()
boost_compiler_flags = boost_config[:compiler_flags]
boost_compiler_flags = boost_config[:compiler_flags]

header_search_paths = [
"$(PODS_ROOT)/boost",
Expand Down Expand Up @@ -69,6 +69,7 @@ Pod::Spec.new do |s|
s.dependency "React-Mapbuffer"
s.dependency "React-jserrorhandler"
s.dependency "React-jsinspector"
s.dependency "React-featureflags"

if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1"
s.dependency "hermes-engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#import <cxxreact/ReactMarker.h>
#import <jsinspector-modern/ReactCdp.h>
#import <jsireact/JSIExecutor.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>
#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
#import <react/utils/ContextContainer.h>
#import <react/utils/ManagedObjectWrapper.h>
Expand Down Expand Up @@ -327,7 +328,7 @@ - (void)_start
});
RCTInstallNativeComponentRegistryBinding(runtime);

if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
if (ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) {
installLegacyUIManagerConstantsProviderBinding(runtime);
}

Expand Down

0 comments on commit 6fc500e

Please sign in to comment.