-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from jpudysz/2.0
v.2.0
- Loading branch information
Showing
231 changed files
with
16,155 additions
and
6,693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
cmake_minimum_required(VERSION 3.9.0) | ||
|
||
project(unistyles) | ||
|
||
add_library(unistyles | ||
SHARED | ||
../cxx/UnistylesRuntime.cpp | ||
./src/main/cxx/cpp-adapter.cpp | ||
) | ||
|
||
include_directories( | ||
../cxx | ||
) | ||
|
||
set_target_properties(unistyles PROPERTIES | ||
CXX_STANDARD 17 | ||
CXX_STANDARD_REQUIRED ON | ||
CXX_EXTENSIONS OFF | ||
POSITION_INDEPENDENT_CODE ON | ||
) | ||
|
||
find_package(ReactAndroid REQUIRED CONFIG) | ||
|
||
target_link_libraries(unistyles | ||
ReactAndroid::jsi | ||
android | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
buildscript { | ||
ext.safeExtGet = {prop, fallback -> | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
repositories { | ||
google() | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
classpath("com.android.tools.build:gradle:7.3.1") | ||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22") | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'org.jetbrains.kotlin.android' | ||
|
||
def resolveBuildType() { | ||
Gradle gradle = getGradle() | ||
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString() | ||
|
||
return tskReqStr.contains('Release') ? 'release' : 'debug' | ||
} | ||
|
||
def isNewArchitectureEnabled() { | ||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" | ||
} | ||
|
||
if (isNewArchitectureEnabled()) { | ||
apply plugin: 'com.facebook.react' | ||
} | ||
|
||
android { | ||
compileSdkVersion safeExtGet('compileSdkVersion', 33) | ||
namespace "com.unistyles" | ||
|
||
defaultConfig { | ||
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() | ||
minSdkVersion safeExtGet('minSdkVersion', 21) | ||
externalNativeBuild { | ||
cmake { | ||
arguments "-DANDROID_STL=c++_shared" | ||
} | ||
} | ||
} | ||
|
||
buildFeatures { | ||
prefab true | ||
} | ||
|
||
externalNativeBuild { | ||
cmake { | ||
path "CMakeLists.txt" | ||
} | ||
} | ||
|
||
packagingOptions { | ||
doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : '' | ||
excludes = [ | ||
"META-INF", | ||
"META-INF/**", | ||
"**/libjsi.so", | ||
"**/libc++_shared.so" | ||
] | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
google() | ||
} | ||
|
||
dependencies { | ||
implementation 'com.facebook.react:react-native' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include <jni.h> | ||
#include <jsi/jsi.h> | ||
#include "UnistylesRuntime.h" | ||
|
||
using namespace facebook; | ||
|
||
static jobject unistylesModule = nullptr; | ||
std::shared_ptr<UnistylesRuntime> unistylesRuntime = nullptr; | ||
|
||
void throwKotlinException( | ||
JNIEnv *env, | ||
const char *message | ||
) { | ||
jclass runtimeExceptionClass = env->FindClass("java/lang/RuntimeException"); | ||
|
||
if (runtimeExceptionClass != nullptr) { | ||
env->ThrowNew(runtimeExceptionClass, message); | ||
env->DeleteLocalRef(runtimeExceptionClass); | ||
} | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT void JNICALL | ||
Java_com_unistyles_UnistylesModule_nativeInstall( | ||
JNIEnv *env, | ||
jobject thiz, | ||
jlong jsi, | ||
jint screenWidth, | ||
jint screenHeight, | ||
jstring colorScheme | ||
) { | ||
auto runtime = reinterpret_cast<facebook::jsi::Runtime *>(jsi); | ||
|
||
if (unistylesModule == nullptr) { | ||
unistylesModule = env->NewGlobalRef(thiz); | ||
} | ||
|
||
if (runtime == nullptr || unistylesModule == nullptr) { | ||
return throwKotlinException(env, "Something went wrong while initializing UnistylesModule"); | ||
} | ||
|
||
const char *colorSchemeChars = env->GetStringUTFChars(colorScheme, nullptr); | ||
std::string colorSchemeStr(colorSchemeChars); | ||
env->ReleaseStringUTFChars(colorScheme, colorSchemeChars); | ||
|
||
unistylesRuntime = std::make_shared<UnistylesRuntime>( | ||
screenWidth, | ||
screenHeight, | ||
colorSchemeStr | ||
); | ||
|
||
unistylesRuntime->onThemeChange([=](const std::string &theme) { | ||
jstring themeStr = env->NewStringUTF(theme.c_str()); | ||
jclass cls = env->GetObjectClass(unistylesModule); | ||
jmethodID methodId = env->GetMethodID(cls, "onThemeChange", "(Ljava/lang/String;)V"); | ||
|
||
env->CallVoidMethod(unistylesModule, methodId, themeStr); | ||
env->DeleteLocalRef(themeStr); | ||
env->DeleteLocalRef(cls); | ||
}); | ||
|
||
unistylesRuntime->onLayoutChange([=](const std::string &breakpoint, const std::string &orientation, int width, int height) { | ||
jstring breakpointStr = env->NewStringUTF(breakpoint.c_str()); | ||
jstring orientationStr = env->NewStringUTF(orientation.c_str()); | ||
jclass cls = env->GetObjectClass(unistylesModule); | ||
jmethodID methodId = env->GetMethodID(cls, "onLayoutChange", "(Ljava/lang/String;Ljava/lang/String;II)V"); | ||
|
||
env->CallVoidMethod(unistylesModule, methodId, breakpointStr, orientationStr, width, height); | ||
env->DeleteLocalRef(breakpointStr); | ||
env->DeleteLocalRef(orientationStr); | ||
env->DeleteLocalRef(cls); | ||
}); | ||
|
||
unistylesRuntime->onPluginChange([=]() { | ||
jclass cls = env->GetObjectClass(unistylesModule); | ||
jmethodID methodId = env->GetMethodID(cls, "onPluginChange", "()V"); | ||
|
||
env->CallVoidMethod(unistylesModule, methodId); | ||
env->DeleteLocalRef(cls); | ||
}); | ||
|
||
jsi::Object hostObject = jsi::Object::createFromHostObject(*runtime, unistylesRuntime); | ||
|
||
runtime->global().setProperty(*runtime, "__UNISTYLES__", std::move(hostObject)); | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT void JNICALL | ||
Java_com_unistyles_UnistylesModule_nativeDestroy(JNIEnv *env, jobject thiz) { | ||
unistylesRuntime.reset(); | ||
unistylesModule = nullptr; | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT void JNICALL | ||
Java_com_unistyles_UnistylesModule_nativeOnOrientationChange(JNIEnv *env, jobject thiz, jint width, jint height) { | ||
if (unistylesRuntime != nullptr) { | ||
unistylesRuntime->handleScreenSizeChange(width, height); | ||
} | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT void JNICALL | ||
Java_com_unistyles_UnistylesModule_nativeOnAppearanceChange(JNIEnv *env, jobject thiz, jstring colorScheme) { | ||
if (unistylesRuntime != nullptr) { | ||
unistylesRuntime->handleAppearanceChange(env->GetStringUTFChars(colorScheme, nullptr)); | ||
} | ||
} |
Oops, something went wrong.