Skip to content

Commit

Permalink
chore: support android
Browse files Browse the repository at this point in the history
  • Loading branch information
WadhahEssam committed Oct 15, 2024
1 parent 77ff3f6 commit 4e0ffd6
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
69 changes: 69 additions & 0 deletions android/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
22 changes: 22 additions & 0 deletions android/src/main/jni/JBAnimatedText.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/TurboModule.h>
#include <jsi/jsi.h>
#include <react/renderer/components/JBAnimatedText/ParagraphComponentDescriptor.h>

namespace facebook {
namespace react {

JSI_EXPORT
std::shared_ptr<TurboModule> JBAnimatedText_ModuleProvider(
const std::string &moduleName,
const JavaTurboModule::InitParams &params) {

// Ensure moduleName matches the expected name
return nullptr;
}


} // namespace react
} // namespace facebook
14 changes: 12 additions & 2 deletions react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
};

0 comments on commit 4e0ffd6

Please sign in to comment.