Skip to content

Commit fc8c7c9

Browse files
committed
feat(lib): added initial impl and tested work on android
1 parent af638c4 commit fc8c7c9

Some content is hidden

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

62 files changed

+19994
-28
lines changed

babel.config.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1-
module.exports = {
2-
presets: ['module:@react-native/babel-preset'],
1+
// @ts-check
2+
/** @type {import('@babel/core').ConfigFunction} */
3+
module.exports = (api) => {
4+
if (api.env() === 'test') {
5+
return {
6+
presets: [
7+
['@babel/preset-env', { targets: { node: 'current' } }],
8+
'@babel/preset-typescript',
9+
],
10+
// include: [
11+
// 'src/**/*',
12+
// 'node_modules/react-native-reanimated',
13+
// 'node_modules/react-native',
14+
// 'node_modules/@react-native',
15+
// ],
16+
plugins: ['@babel/plugin-transform-flow-strip-types'],
17+
};
18+
}
19+
return {
20+
presets: ['module:@react-native/babel-preset'],
21+
};
322
};

example/android/.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Android/IntelliJ
6+
#
7+
build/
8+
.idea
9+
.gradle
10+
local.properties
11+
*.iml
12+
*.hprof
13+
14+
# Bundle artifacts
15+
*.jsbundle

example/android/app/build.gradle

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
apply plugin: "com.android.application"
2+
apply plugin: "org.jetbrains.kotlin.android"
3+
apply plugin: "com.facebook.react"
4+
5+
def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
6+
7+
/**
8+
* This is the configuration block to customize your React Native Android app.
9+
* By default you don't need to apply any configuration, just uncomment the lines you need.
10+
*/
11+
react {
12+
entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
13+
reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
14+
hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
15+
codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
16+
17+
// Use Expo CLI to bundle the app, this ensures the Metro config
18+
// works correctly with Expo projects.
19+
cliFile = new File(["node", "--print", "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })"].execute(null, rootDir).text.trim())
20+
bundleCommand = "export:embed"
21+
22+
/* Folders */
23+
// The root of your project, i.e. where "package.json" lives. Default is '..'
24+
// root = file("../")
25+
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
26+
// reactNativeDir = file("../node_modules/react-native")
27+
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
28+
// codegenDir = file("../node_modules/@react-native/codegen")
29+
30+
/* Variants */
31+
// The list of variants to that are debuggable. For those we're going to
32+
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
33+
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
34+
// debuggableVariants = ["liteDebug", "prodDebug"]
35+
36+
/* Bundling */
37+
// A list containing the node command and its flags. Default is just 'node'.
38+
// nodeExecutableAndArgs = ["node"]
39+
40+
//
41+
// The path to the CLI configuration file. Default is empty.
42+
// bundleConfig = file(../rn-cli.config.js)
43+
//
44+
// The name of the generated asset file containing your JS bundle
45+
// bundleAssetName = "MyApplication.android.bundle"
46+
//
47+
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
48+
// entryFile = file("../js/MyApplication.android.js")
49+
//
50+
// A list of extra flags to pass to the 'bundle' commands.
51+
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
52+
// extraPackagerArgs = []
53+
54+
/* Hermes Commands */
55+
// The hermes compiler command to run. By default it is 'hermesc'
56+
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
57+
//
58+
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
59+
// hermesFlags = ["-O", "-output-source-map"]
60+
}
61+
62+
/**
63+
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
64+
*/
65+
def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: false).toBoolean()
66+
67+
/**
68+
* The preferred build flavor of JavaScriptCore (JSC)
69+
*
70+
* For example, to use the international variant, you can use:
71+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
72+
*
73+
* The international variant includes ICU i18n library and necessary data
74+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
75+
* give correct results when using with locales other than en-US. Note that
76+
* this variant is about 6MiB larger per architecture than default.
77+
*/
78+
def jscFlavor = 'org.webkit:android-jsc:+'
79+
80+
android {
81+
ndkVersion rootProject.ext.ndkVersion
82+
83+
buildToolsVersion rootProject.ext.buildToolsVersion
84+
compileSdk rootProject.ext.compileSdkVersion
85+
86+
namespace 'com.skia_ui.example'
87+
defaultConfig {
88+
applicationId 'com.skia_ui.example'
89+
minSdkVersion rootProject.ext.minSdkVersion
90+
targetSdkVersion rootProject.ext.targetSdkVersion
91+
versionCode 1
92+
versionName "1.0.0"
93+
94+
buildConfigField("boolean", "REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS", (findProperty("reactNative.unstable_useRuntimeSchedulerAlways") ?: true).toString())
95+
}
96+
signingConfigs {
97+
debug {
98+
storeFile file('debug.keystore')
99+
storePassword 'android'
100+
keyAlias 'androiddebugkey'
101+
keyPassword 'android'
102+
}
103+
}
104+
buildTypes {
105+
debug {
106+
signingConfig signingConfigs.debug
107+
}
108+
release {
109+
// Caution! In production, you need to generate your own keystore file.
110+
// see https://reactnative.dev/docs/signed-apk-android.
111+
signingConfig signingConfigs.debug
112+
shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
113+
minifyEnabled enableProguardInReleaseBuilds
114+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
115+
}
116+
}
117+
packagingOptions {
118+
jniLibs {
119+
useLegacyPackaging (findProperty('expo.useLegacyPackaging')?.toBoolean() ?: false)
120+
}
121+
}
122+
}
123+
124+
// Apply static values from `gradle.properties` to the `android.packagingOptions`
125+
// Accepts values in comma delimited lists, example:
126+
// android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
127+
["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
128+
// Split option: 'foo,bar' -> ['foo', 'bar']
129+
def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
130+
// Trim all elements in place.
131+
for (i in 0..<options.size()) options[i] = options[i].trim();
132+
// `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
133+
options -= ""
134+
135+
if (options.length > 0) {
136+
println "android.packagingOptions.$prop += $options ($options.length)"
137+
// Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
138+
options.each {
139+
android.packagingOptions[prop] += it
140+
}
141+
}
142+
}
143+
144+
dependencies {
145+
// The version of react-native is set by the React Native Gradle Plugin
146+
implementation("com.facebook.react:react-android")
147+
148+
def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
149+
def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
150+
def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";
151+
152+
if (isGifEnabled) {
153+
// For animated gif support
154+
implementation("com.facebook.fresco:animated-gif:${reactAndroidLibs.versions.fresco.get()}")
155+
}
156+
157+
if (isWebpEnabled) {
158+
// For webp support
159+
implementation("com.facebook.fresco:webpsupport:${reactAndroidLibs.versions.fresco.get()}")
160+
if (isWebpAnimatedEnabled) {
161+
// Animated webp support
162+
implementation("com.facebook.fresco:animated-webp:${reactAndroidLibs.versions.fresco.get()}")
163+
}
164+
}
165+
166+
implementation("com.facebook.react:flipper-integration")
167+
168+
if (hermesEnabled.toBoolean()) {
169+
implementation("com.facebook.react:hermes-android")
170+
} else {
171+
implementation jscFlavor
172+
}
173+
}
174+
175+
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
176+
applyNativeModulesAppBuildGradle(project)

example/android/app/debug.keystore

2.2 KB
Binary file not shown.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
# react-native-reanimated
11+
-keep class com.swmansion.reanimated.** { *; }
12+
-keep class com.facebook.react.turbomodule.** { *; }
13+
14+
# Add any project specific keep options here:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools">
3+
4+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
5+
6+
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" tools:replace="android:usesCleartextTraffic" />
7+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.INTERNET"/>
3+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
4+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
5+
<uses-permission android:name="android.permission.VIBRATE"/>
6+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
7+
<queries>
8+
<intent>
9+
<action android:name="android.intent.action.VIEW"/>
10+
<category android:name="android.intent.category.BROWSABLE"/>
11+
<data android:scheme="https"/>
12+
</intent>
13+
</queries>
14+
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme">
15+
<meta-data android:name="expo.modules.updates.ENABLED" android:value="false"/>
16+
<meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="50.0.0"/>
17+
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
18+
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
19+
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN"/>
22+
<category android:name="android.intent.category.LAUNCHER"/>
23+
</intent-filter>
24+
<intent-filter>
25+
<action android:name="android.intent.action.VIEW"/>
26+
<category android:name="android.intent.category.DEFAULT"/>
27+
<category android:name="android.intent.category.BROWSABLE"/>
28+
<data android:scheme="com.skia_ui.example"/>
29+
<data android:scheme="exp+example"/>
30+
</intent-filter>
31+
</activity>
32+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/>
33+
</application>
34+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.skia_ui.example
2+
3+
import android.os.Build
4+
import android.os.Bundle
5+
6+
import com.facebook.react.ReactActivity
7+
import com.facebook.react.ReactActivityDelegate
8+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
9+
import com.facebook.react.defaults.DefaultReactActivityDelegate
10+
11+
import expo.modules.ReactActivityDelegateWrapper
12+
13+
class MainActivity : ReactActivity() {
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
// Set the theme to AppTheme BEFORE onCreate to support
16+
// coloring the background, status bar, and navigation bar.
17+
// This is required for expo-splash-screen.
18+
setTheme(R.style.AppTheme);
19+
super.onCreate(null)
20+
}
21+
22+
/**
23+
* Returns the name of the main component registered from JavaScript. This is used to schedule
24+
* rendering of the component.
25+
*/
26+
override fun getMainComponentName(): String = "main"
27+
28+
/**
29+
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
30+
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
31+
*/
32+
override fun createReactActivityDelegate(): ReactActivityDelegate {
33+
return ReactActivityDelegateWrapper(
34+
this,
35+
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
36+
object : DefaultReactActivityDelegate(
37+
this,
38+
mainComponentName,
39+
fabricEnabled
40+
){})
41+
}
42+
43+
/**
44+
* Align the back button behavior with Android S
45+
* where moving root activities to background instead of finishing activities.
46+
* @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a>
47+
*/
48+
override fun invokeDefaultOnBackPressed() {
49+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
50+
if (!moveTaskToBack(false)) {
51+
// For non-root activities, use the default implementation to finish them.
52+
super.invokeDefaultOnBackPressed()
53+
}
54+
return
55+
}
56+
57+
// Use the default back button implementation on Android S
58+
// because it's doing more than [Activity.moveTaskToBack] in fact.
59+
super.invokeDefaultOnBackPressed()
60+
}
61+
}

0 commit comments

Comments
 (0)