Skip to content

Commit

Permalink
Reduce number of generated files for the feature flags system (facebo…
Browse files Browse the repository at this point in the history
…ok#42820)

Summary:
Pull Request resolved: facebook#42820

The feature flag system generates a significant amount of files. This reduces that number to remove noise from diffs/PRs by eliminating a file that could be defined privately within another one.

Changelog: [internal]

Reviewed By: huntie

Differential Revision: D53352391

fbshipit-source-id: 51fccb3c1bb09ef3503cd34334d28c1021bd1b25
  • Loading branch information
rubennorte authored and facebook-github-bot committed Feb 5, 2024
1 parent 5030f4e commit e035005
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e570b62b4a208b2526169361c3a6be6a>>
* @generated SignedSource<<18e31d0833fda8cfb3f31b449479297a>>
*/

/**
Expand All @@ -19,10 +19,72 @@

#include "JReactNativeFeatureFlagsCxxInterop.h"
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/featureflags/ReactNativeFeatureFlagsProviderHolder.h>

namespace facebook::react {

static jni::alias_ref<jni::JClass> getReactNativeFeatureFlagsProviderJavaClass() {
static const auto jClass = facebook::jni::findClassStatic(
"com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider");
return jClass;
}

/**
* Implementation of ReactNativeFeatureFlagsProvider that wraps a
* ReactNativeFeatureFlagsProvider Java object.
*/
class ReactNativeFeatureFlagsProviderHolder
: public ReactNativeFeatureFlagsProvider {
public:
explicit ReactNativeFeatureFlagsProviderHolder(
jni::alias_ref<jobject> javaProvider)
: javaProvider_(make_global(javaProvider)){};

bool commonTestFlag() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("commonTestFlag");
return method(javaProvider_);
}

bool useModernRuntimeScheduler() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useModernRuntimeScheduler");
return method(javaProvider_);
}

bool enableMicrotasks() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableMicrotasks");
return method(javaProvider_);
}

bool batchRenderingUpdatesInEventLoop() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("batchRenderingUpdatesInEventLoop");
return method(javaProvider_);
}

bool enableSpannableBuildingUnification() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableSpannableBuildingUnification");
return method(javaProvider_);
}

bool enableCustomDrawOrderFabric() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableCustomDrawOrderFabric");
return method(javaProvider_);
}

bool enableFixForClippedSubviewsCrash() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableFixForClippedSubviewsCrash");
return method(javaProvider_);
}

private:
jni::global_ref<jobject> javaProvider_;
};

bool JReactNativeFeatureFlagsCxxInterop::commonTestFlag(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::commonTestFlag();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import ReactNativeFeatureFlagsCxxInteropKt from './templates/android/ReactNative
import ReactNativeFeatureFlagsDefaultsKt from './templates/android/ReactNativeFeatureFlagsDefaults.kt-template';
import ReactNativeFeatureFlagsLocalAccessorKt from './templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template';
import ReactNativeFeatureFlagsProviderKt from './templates/android/ReactNativeFeatureFlagsProvider.kt-template';
import ReactNativeFeatureFlagsProviderHolderCPP from './templates/android/ReactNativeFeatureFlagsProviderHolder.cpp-template';
import ReactNativeFeatureFlagsProviderHolderH from './templates/android/ReactNativeFeatureFlagsProviderHolder.h-template';
import path from 'path';

export default function generateAndroidModules(
Expand All @@ -40,10 +38,6 @@ export default function generateAndroidModules(
ReactNativeFeatureFlagsDefaultsKt(featureFlagDefinitions),
[path.join(androidPath, 'ReactNativeFeatureFlagsProvider.kt')]:
ReactNativeFeatureFlagsProviderKt(featureFlagDefinitions),
[path.join(androidJniPath, 'ReactNativeFeatureFlagsProviderHolder.h')]:
ReactNativeFeatureFlagsProviderHolderH(featureFlagDefinitions),
[path.join(androidJniPath, 'ReactNativeFeatureFlagsProviderHolder.cpp')]:
ReactNativeFeatureFlagsProviderHolderCPP(featureFlagDefinitions),
[path.join(androidJniPath, 'JReactNativeFeatureFlagsCxxInterop.h')]:
JReactNativeFeatureFlagsCxxInteropH(featureFlagDefinitions),
[path.join(androidJniPath, 'JReactNativeFeatureFlagsCxxInterop.cpp')]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,43 @@ ${DO_NOT_MODIFY_COMMENT}
#include "JReactNativeFeatureFlagsCxxInterop.h"
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/featureflags/ReactNativeFeatureFlagsProviderHolder.h>
namespace facebook::react {
static jni::alias_ref<jni::JClass> getReactNativeFeatureFlagsProviderJavaClass() {
static const auto jClass = facebook::jni::findClassStatic(
"com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider");
return jClass;
}
/**
* Implementation of ReactNativeFeatureFlagsProvider that wraps a
* ReactNativeFeatureFlagsProvider Java object.
*/
class ReactNativeFeatureFlagsProviderHolder
: public ReactNativeFeatureFlagsProvider {
public:
explicit ReactNativeFeatureFlagsProviderHolder(
jni::alias_ref<jobject> javaProvider)
: javaProvider_(make_global(javaProvider)){};
${Object.entries(definitions.common)
.map(
([flagName, flagConfig]) =>
` ${getCxxTypeFromDefaultValue(
flagConfig.defaultValue,
)} ${flagName}() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("${flagName}");
return method(javaProvider_);
}`,
)
.join('\n\n')}
private:
jni::global_ref<jobject> javaProvider_;
};
${Object.entries(definitions.common)
.map(
([flagName, flagConfig]) =>
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit e035005

Please sign in to comment.