From 4e0ffd634e8dd55229ce5e81d93fb0484f52f96e Mon Sep 17 00:00:00 2001 From: Wadah Esam Date: Tue, 15 Oct 2024 21:57:47 +0300 Subject: [PATCH] chore: support android --- android/src/main/jni/CMakeLists.txt | 69 +++++++++++++++++++++++++++ android/src/main/jni/JBAnimatedText.h | 22 +++++++++ react-native.config.js | 14 +++++- 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 android/src/main/jni/CMakeLists.txt create mode 100644 android/src/main/jni/JBAnimatedText.h diff --git a/android/src/main/jni/CMakeLists.txt b/android/src/main/jni/CMakeLists.txt new file mode 100644 index 0000000..b7115e6 --- /dev/null +++ b/android/src/main/jni/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.13) +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_CXX_STANDARD 20) + +set(LIB_LITERAL JBAnimatedText) +set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL}) + +set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +set(LIB_CPP_DIR ${LIB_ANDROID_DIR}/../cpp) +set(LIB_CUSTOM_SOURCES_DIR ${LIB_CPP_DIR}/react/renderer/components/${LIB_LITERAL}) +set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni) +set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL}) + +file(GLOB LIB_MODULE_SRCS CONFIGURE_DEPENDS *.cpp) +file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS ${LIB_CUSTOM_SOURCES_DIR}/*.cpp) +file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp) + +set(RN_DIR ${LIB_ANDROID_DIR}/../example/node_modules/react-native) + +add_library( + ${LIB_TARGET_NAME} + SHARED + ${LIB_MODULE_SRCS} + ${LIB_CUSTOM_SRCS} + ${LIB_CODEGEN_SRCS} +) + +target_include_directories( + ${LIB_TARGET_NAME} + PUBLIC + . + ${LIB_ANDROID_GENERATED_JNI_DIR} + ${LIB_ANDROID_GENERATED_COMPONENTS_DIR} + ${LIB_CPP_DIR} +) + +find_package(fbjni REQUIRED CONFIG) +find_package(ReactAndroid REQUIRED CONFIG) + +target_link_libraries( + ${LIB_TARGET_NAME} + fbjni::fbjni + ReactAndroid::jsi +) + +if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76) + target_link_libraries( + ${LIB_TARGET_NAME} + ReactAndroid::reactnative + ) +else () + message(FATAL_ERROR "react-native-live-markdown requires react-native 0.76 or newer.") +endif () + +target_compile_options( + ${LIB_TARGET_NAME} + PRIVATE + -DLOG_TAG=\"ReactNative\" + -fexceptions + -frtti + -Wall + -std=c++20 +) + +target_include_directories( + ${CMAKE_PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/android/src/main/jni/JBAnimatedText.h b/android/src/main/jni/JBAnimatedText.h new file mode 100644 index 0000000..e023348 --- /dev/null +++ b/android/src/main/jni/JBAnimatedText.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +namespace facebook { +namespace react { + +JSI_EXPORT +std::shared_ptr JBAnimatedText_ModuleProvider( + const std::string &moduleName, + const JavaTurboModule::InitParams ¶ms) { + + // Ensure moduleName matches the expected name + return nullptr; +} + + +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/react-native.config.js b/react-native.config.js index 9b67c56..96e5169 100644 --- a/react-native.config.js +++ b/react-native.config.js @@ -2,5 +2,15 @@ * @type {import('@react-native-community/cli-types').UserDependencyConfig} */ module.exports = { - dependency: {}, -}; + dependency: { + platforms: { + android: { + libraryName: 'JBAnimatedText', + componentDescriptors: ['CParagraphComponentDescriptor'], + cmakeListsPath: '../android/src/main/jni/CMakeLists.txt', + }, + macos: null, + windows: null, + }, + }, +}; \ No newline at end of file