Skip to content

Commit f411c51

Browse files
authored
Merge pull request changwoolab#1 from changwoolab/@wolewicki/add-fabric
Add Fabric
2 parents 9ab80fc + 71dc8be commit f411c51

File tree

111 files changed

+10882
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+10882
-69
lines changed

FabricExample/.bundle/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

FabricExample/.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native',
4+
};

FabricExample/.gitignore

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
ios/.xcode.env.local
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
32+
*.hprof
33+
.cxx/
34+
*.keystore
35+
!debug.keystore
36+
37+
# node.js
38+
#
39+
node_modules/
40+
npm-debug.log
41+
yarn-error.log
42+
43+
# fastlane
44+
#
45+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
46+
# screenshots whenever they are needed.
47+
# For more information about the recommended setup visit:
48+
# https://docs.fastlane.tools/best-practices/source-control/
49+
50+
**/fastlane/report.xml
51+
**/fastlane/Preview.html
52+
**/fastlane/screenshots
53+
**/fastlane/test_output
54+
55+
# Bundle artifact
56+
*.jsbundle
57+
58+
# Ruby / CocoaPods
59+
/ios/Pods/
60+
/vendor/bundle/
61+
62+
# Temporary files created by Metro to check the health of the file watcher
63+
.metro-health-check*
64+
65+
# testing
66+
/coverage

FabricExample/.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
arrowParens: 'avoid',
3+
bracketSameLine: true,
4+
bracketSpacing: false,
5+
singleQuote: true,
6+
trailingComma: 'all',
7+
};

FabricExample/.watchmanconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

FabricExample/Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'https://rubygems.org'
2+
3+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4+
ruby ">= 2.6.10"
5+
6+
gem 'cocoapods', '~> 1.12'

FabricExample/__tests__/App.test.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import App from '../App';
8+
9+
// Note: import explicitly to use the types shiped with jest.
10+
import {it} from '@jest/globals';
11+
12+
// Note: test renderer must be required after react-native.
13+
import renderer from 'react-test-renderer';
14+
15+
it('renders correctly', () => {
16+
renderer.create(<App />);
17+
});
+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
apply plugin: "com.android.application"
2+
apply plugin: "com.facebook.react"
3+
4+
/**
5+
* This is the configuration block to customize your React Native Android app.
6+
* By default you don't need to apply any configuration, just uncomment the lines you need.
7+
*/
8+
react {
9+
/* Folders */
10+
// The root of your project, i.e. where "package.json" lives. Default is '..'
11+
// root = file("../")
12+
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
13+
// reactNativeDir = file("../node_modules/react-native")
14+
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
15+
// codegenDir = file("../node_modules/@react-native/codegen")
16+
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
17+
// cliFile = file("../node_modules/react-native/cli.js")
18+
19+
/* Variants */
20+
// The list of variants to that are debuggable. For those we're going to
21+
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
22+
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
23+
// debuggableVariants = ["liteDebug", "prodDebug"]
24+
25+
/* Bundling */
26+
// A list containing the node command and its flags. Default is just 'node'.
27+
// nodeExecutableAndArgs = ["node"]
28+
//
29+
// The command to run when bundling. By default is 'bundle'
30+
// bundleCommand = "ram-bundle"
31+
//
32+
// The path to the CLI configuration file. Default is empty.
33+
// bundleConfig = file(../rn-cli.config.js)
34+
//
35+
// The name of the generated asset file containing your JS bundle
36+
// bundleAssetName = "MyApplication.android.bundle"
37+
//
38+
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
39+
// entryFile = file("../js/MyApplication.android.js")
40+
//
41+
// A list of extra flags to pass to the 'bundle' commands.
42+
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
43+
// extraPackagerArgs = []
44+
45+
/* Hermes Commands */
46+
// The hermes compiler command to run. By default it is 'hermesc'
47+
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
48+
//
49+
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
50+
// hermesFlags = ["-O", "-output-source-map"]
51+
}
52+
53+
/**
54+
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
55+
*/
56+
def enableProguardInReleaseBuilds = false
57+
58+
/**
59+
* The preferred build flavor of JavaScriptCore (JSC)
60+
*
61+
* For example, to use the international variant, you can use:
62+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
63+
*
64+
* The international variant includes ICU i18n library and necessary data
65+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
66+
* give correct results when using with locales other than en-US. Note that
67+
* this variant is about 6MiB larger per architecture than default.
68+
*/
69+
def jscFlavor = 'org.webkit:android-jsc:+'
70+
71+
android {
72+
ndkVersion rootProject.ext.ndkVersion
73+
74+
compileSdkVersion rootProject.ext.compileSdkVersion
75+
76+
namespace "com.fabricexample"
77+
defaultConfig {
78+
applicationId "com.fabricexample"
79+
minSdkVersion rootProject.ext.minSdkVersion
80+
targetSdkVersion rootProject.ext.targetSdkVersion
81+
versionCode 1
82+
versionName "1.0"
83+
}
84+
signingConfigs {
85+
debug {
86+
storeFile file('debug.keystore')
87+
storePassword 'android'
88+
keyAlias 'androiddebugkey'
89+
keyPassword 'android'
90+
}
91+
}
92+
buildTypes {
93+
debug {
94+
signingConfig signingConfigs.debug
95+
}
96+
release {
97+
// Caution! In production, you need to generate your own keystore file.
98+
// see https://reactnative.dev/docs/signed-apk-android.
99+
signingConfig signingConfigs.debug
100+
minifyEnabled enableProguardInReleaseBuilds
101+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
102+
}
103+
}
104+
}
105+
106+
dependencies {
107+
// The version of react-native is set by the React Native Gradle Plugin
108+
implementation("com.facebook.react:react-android")
109+
110+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
111+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
112+
exclude group:'com.squareup.okhttp3', module:'okhttp'
113+
}
114+
115+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
116+
if (hermesEnabled.toBoolean()) {
117+
implementation("com.facebook.react:hermes-android")
118+
} else {
119+
implementation jscFlavor
120+
}
121+
}
122+
123+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
2.2 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
6+
7+
<application
8+
android:usesCleartextTraffic="true"
9+
tools:targetApi="28"
10+
tools:ignore="GoogleAppIndexingWarning">
11+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
12+
</application>
13+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
5+
* directory of this source tree.
6+
*/
7+
package com.fabricexample;
8+
9+
import android.content.Context;
10+
import com.facebook.flipper.android.AndroidFlipperClient;
11+
import com.facebook.flipper.android.utils.FlipperUtils;
12+
import com.facebook.flipper.core.FlipperClient;
13+
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
14+
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
15+
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
16+
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
17+
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
18+
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
19+
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20+
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
21+
import com.facebook.react.ReactInstanceEventListener;
22+
import com.facebook.react.ReactInstanceManager;
23+
import com.facebook.react.bridge.ReactContext;
24+
import com.facebook.react.modules.network.NetworkingModule;
25+
import okhttp3.OkHttpClient;
26+
27+
/**
28+
* Class responsible of loading Flipper inside your React Native application. This is the debug
29+
* flavor of it. Here you can add your own plugins and customize the Flipper setup.
30+
*/
31+
public class ReactNativeFlipper {
32+
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
33+
if (FlipperUtils.shouldEnableFlipper(context)) {
34+
final FlipperClient client = AndroidFlipperClient.getInstance(context);
35+
36+
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
37+
client.addPlugin(new DatabasesFlipperPlugin(context));
38+
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
39+
client.addPlugin(CrashReporterPlugin.getInstance());
40+
41+
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
42+
NetworkingModule.setCustomClientBuilder(
43+
new NetworkingModule.CustomClientBuilder() {
44+
@Override
45+
public void apply(OkHttpClient.Builder builder) {
46+
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
47+
}
48+
});
49+
client.addPlugin(networkFlipperPlugin);
50+
client.start();
51+
52+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
53+
// Hence we run if after all native modules have been initialized
54+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
55+
if (reactContext == null) {
56+
reactInstanceManager.addReactInstanceEventListener(
57+
new ReactInstanceEventListener() {
58+
@Override
59+
public void onReactContextInitialized(ReactContext reactContext) {
60+
reactInstanceManager.removeReactInstanceEventListener(this);
61+
reactContext.runOnNativeModulesQueueThread(
62+
new Runnable() {
63+
@Override
64+
public void run() {
65+
client.addPlugin(new FrescoFlipperPlugin());
66+
}
67+
});
68+
}
69+
});
70+
} else {
71+
client.addPlugin(new FrescoFlipperPlugin());
72+
}
73+
}
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
3+
<uses-permission android:name="android.permission.INTERNET" />
4+
5+
<application
6+
android:name=".MainApplication"
7+
android:label="@string/app_name"
8+
android:icon="@mipmap/ic_launcher"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:allowBackup="false"
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name=".MainActivity"
14+
android:label="@string/app_name"
15+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
16+
android:launchMode="singleTask"
17+
android:windowSoftInputMode="adjustResize"
18+
android:exported="true">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fabricexample;
2+
3+
import com.facebook.react.ReactActivity;
4+
import com.facebook.react.ReactActivityDelegate;
5+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
6+
import com.facebook.react.defaults.DefaultReactActivityDelegate;
7+
8+
public class MainActivity extends ReactActivity {
9+
10+
/**
11+
* Returns the name of the main component registered from JavaScript. This is used to schedule
12+
* rendering of the component.
13+
*/
14+
@Override
15+
protected String getMainComponentName() {
16+
return "FabricExample";
17+
}
18+
19+
/**
20+
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
21+
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
22+
* (aka React 18) with two boolean flags.
23+
*/
24+
@Override
25+
protected ReactActivityDelegate createReactActivityDelegate() {
26+
return new DefaultReactActivityDelegate(
27+
this,
28+
getMainComponentName(),
29+
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
30+
DefaultNewArchitectureEntryPoint.getFabricEnabled());
31+
}
32+
}

0 commit comments

Comments
 (0)