@granite-js/screen 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/GraniteScreen.podspec +25 -0
  3. package/LICENSE +202 -0
  4. package/android/CMakeLists.txt +62 -0
  5. package/android/build.gradle +63 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/cpp/BundleEvaluator.cpp +27 -0
  8. package/android/src/main/cpp/BundleEvaluator.h +17 -0
  9. package/android/src/main/cpp/onLoad.cpp +6 -0
  10. package/android/src/main/kotlin/run/granite/BundleEvaluator.kt +50 -0
  11. package/android/src/main/kotlin/run/granite/BundleLoader.kt +40 -0
  12. package/android/src/main/kotlin/run/granite/DefaultBundleLoader.kt +20 -0
  13. package/android/src/main/kotlin/run/granite/DefaultErrorView.kt +58 -0
  14. package/android/src/main/kotlin/run/granite/DefaultLoadingView.kt +51 -0
  15. package/android/src/main/kotlin/run/granite/GraniteReactDelegate.kt +76 -0
  16. package/android/src/main/kotlin/run/granite/GraniteReactDelegateImpl.kt +448 -0
  17. package/android/src/main/kotlin/run/granite/GraniteReactHost.kt +113 -0
  18. package/android/src/main/kotlin/run/granite/ReactHostFactory.kt +106 -0
  19. package/gradle-plugin/LICENSE +201 -0
  20. package/gradle-plugin/README.md +578 -0
  21. package/gradle-plugin/build.gradle.kts +97 -0
  22. package/gradle-plugin/gradle/libs.versions.toml +17 -0
  23. package/gradle-plugin/gradle/wrapper/gradle-wrapper.jar +0 -0
  24. package/gradle-plugin/gradle/wrapper/gradle-wrapper.properties +7 -0
  25. package/gradle-plugin/gradle.properties +12 -0
  26. package/gradle-plugin/gradlew +248 -0
  27. package/gradle-plugin/gradlew.bat +93 -0
  28. package/gradle-plugin/settings.gradle.kts +1 -0
  29. package/gradle-plugin/src/main/kotlin/run/granite/gradle/GraniteExtension.kt +225 -0
  30. package/gradle-plugin/src/main/kotlin/run/granite/gradle/GranitePlugin.kt +784 -0
  31. package/gradle-plugin/src/main/kotlin/run/granite/gradle/GraniteRootExtension.kt +107 -0
  32. package/gradle-plugin/src/main/kotlin/run/granite/gradle/GraniteRootProjectPlugin.kt +290 -0
  33. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/BuildConfigConfigurator.kt +69 -0
  34. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/DependencyConfigurator.kt +232 -0
  35. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/DependencyCoordinates.kt +29 -0
  36. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/DevServerResourceConfigurator.kt +101 -0
  37. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/JniPackagingConfigurator.kt +160 -0
  38. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/NdkConfigurator.kt +135 -0
  39. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/RepositoryConfigurator.kt +148 -0
  40. package/gradle-plugin/src/main/kotlin/run/granite/gradle/config/ResourceConfigurator.kt +56 -0
  41. package/gradle-plugin/src/main/kotlin/run/granite/gradle/generators/CMakeGenerator.kt +105 -0
  42. package/gradle-plugin/src/main/kotlin/run/granite/gradle/generators/CppAutolinkingGenerator.kt +152 -0
  43. package/gradle-plugin/src/main/kotlin/run/granite/gradle/generators/EntryPointGenerator.kt +100 -0
  44. package/gradle-plugin/src/main/kotlin/run/granite/gradle/models/AndroidDependencyConfig.kt +23 -0
  45. package/gradle-plugin/src/main/kotlin/run/granite/gradle/models/AutolinkingConfig.kt +89 -0
  46. package/gradle-plugin/src/main/kotlin/run/granite/gradle/models/CMakeEntry.kt +47 -0
  47. package/gradle-plugin/src/main/kotlin/run/granite/gradle/models/NativeModule.kt +177 -0
  48. package/gradle-plugin/src/main/kotlin/run/granite/gradle/tasks/AssetPackagingTask.kt +194 -0
  49. package/gradle-plugin/src/main/kotlin/run/granite/gradle/tasks/AutolinkingTask.kt +431 -0
  50. package/gradle-plugin/src/main/kotlin/run/granite/gradle/tasks/BundleTask.kt +275 -0
  51. package/gradle-plugin/src/main/kotlin/run/granite/gradle/tasks/CodegenArtifactsTask.kt +218 -0
  52. package/gradle-plugin/src/main/kotlin/run/granite/gradle/tasks/CodegenSchemaTask.kt +186 -0
  53. package/gradle-plugin/src/main/kotlin/run/granite/gradle/utils/AutolinkingParser.kt +128 -0
  54. package/gradle-plugin/src/main/kotlin/run/granite/gradle/utils/ConflictDetector.kt +121 -0
  55. package/gradle-plugin/src/main/kotlin/run/granite/gradle/utils/JdkValidator.kt +73 -0
  56. package/gradle-plugin/src/main/kotlin/run/granite/gradle/utils/NodeExecutableFinder.kt +43 -0
  57. package/gradle-plugin/src/main/kotlin/run/granite/gradle/utils/ReactNativeVersionReader.kt +329 -0
  58. package/gradle-plugin/src/main/kotlin/run/granite/gradle/utils/TaskDependencyValidator.kt +198 -0
  59. package/gradle-plugin/src/test/kotlin/run/granite/gradle/GraniteExtensionTest.kt +191 -0
  60. package/gradle-plugin/src/test/kotlin/run/granite/gradle/GranitePluginTest.kt +156 -0
  61. package/gradle-plugin/src/test/kotlin/run/granite/gradle/GraniteRootProjectPluginTest.kt +87 -0
  62. package/gradle-plugin/src/test/kotlin/run/granite/gradle/config/BuildConfigConfiguratorTest.kt +115 -0
  63. package/gradle-plugin/src/test/kotlin/run/granite/gradle/config/DependencyConfiguratorTest.kt +338 -0
  64. package/gradle-plugin/src/test/kotlin/run/granite/gradle/config/DevServerResourceConfiguratorTest.kt +205 -0
  65. package/gradle-plugin/src/test/kotlin/run/granite/gradle/config/ResourceConfiguratorTest.kt +131 -0
  66. package/gradle-plugin/src/test/kotlin/run/granite/gradle/fixtures/NativeModuleFixtures.kt +67 -0
  67. package/gradle-plugin/src/test/kotlin/run/granite/gradle/generators/CMakeGeneratorTest.kt +71 -0
  68. package/gradle-plugin/src/test/kotlin/run/granite/gradle/generators/CppAutolinkingGeneratorTest.kt +344 -0
  69. package/gradle-plugin/src/test/kotlin/run/granite/gradle/generators/EntryPointGeneratorTest.kt +40 -0
  70. package/gradle-plugin/src/test/kotlin/run/granite/gradle/models/AutolinkingConfigTest.kt +350 -0
  71. package/gradle-plugin/src/test/kotlin/run/granite/gradle/models/CMakeEntryTest.kt +200 -0
  72. package/gradle-plugin/src/test/kotlin/run/granite/gradle/models/NativeModuleTest.kt +562 -0
  73. package/gradle-plugin/src/test/kotlin/run/granite/gradle/tasks/AssetPackagingTaskTest.kt +318 -0
  74. package/gradle-plugin/src/test/kotlin/run/granite/gradle/tasks/AutolinkingTaskTest.kt +89 -0
  75. package/gradle-plugin/src/test/kotlin/run/granite/gradle/tasks/BundleTaskTest.kt +68 -0
  76. package/gradle-plugin/src/test/kotlin/run/granite/gradle/tasks/CodegenTasksTest.kt +410 -0
  77. package/gradle-plugin/src/test/kotlin/run/granite/gradle/utils/AutolinkingParserTest.kt +335 -0
  78. package/gradle-plugin/src/test/kotlin/run/granite/gradle/utils/ConflictDetectorTest.kt +75 -0
  79. package/gradle-plugin/src/test/kotlin/run/granite/gradle/utils/JdkValidatorTest.kt +88 -0
  80. package/gradle-plugin/src/test/kotlin/run/granite/gradle/utils/ReactNativeVersionReaderTest.kt +585 -0
  81. package/gradle-plugin/src/test/kotlin/run/granite/gradle/utils/TaskDependencyValidatorTest.kt +123 -0
  82. package/gradle-plugin/src/test/kotlin/run/granite/gradle/utils/TaskTestUtils.kt +88 -0
  83. package/gradle-plugin/src/test/resources/fixtures/sample-rn-config.json +45 -0
  84. package/ios/BundleLoader/BundleEvaluator.h +16 -0
  85. package/ios/BundleLoader/BundleEvaluator.mm +76 -0
  86. package/ios/BundleLoader/BundleLoadable.swift +91 -0
  87. package/ios/GraniteBundleLoaderTypes.swift +7 -0
  88. package/ios/GraniteScreen.h +12 -0
  89. package/ios/ReactNativeHosting/DefaultViews.swift +138 -0
  90. package/ios/ReactNativeHosting/GraniteDefaultModuleProvider.h +24 -0
  91. package/ios/ReactNativeHosting/GraniteDefaultModuleProvider.mm +22 -0
  92. package/ios/ReactNativeHosting/GraniteHostingHelper.swift +103 -0
  93. package/ios/ReactNativeHosting/GraniteNativeFactory.swift +35 -0
  94. package/ios/ReactNativeHosting/GraniteNativeFactoryDelegateImpl.swift +30 -0
  95. package/ios/ReactNativeHosting/GraniteNativeFactoryImpl.swift +24 -0
  96. package/ios/ReactNativeHosting/GraniteReactHost.swift +39 -0
  97. package/ios/ReactNativeHosting/GraniteScreen-Bridging-Header.h +12 -0
  98. package/package.json +59 -0
  99. package/react-native.config.js +8 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @granite-js/screen
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 260daab: feat: introduce support react native 0.84
@@ -0,0 +1,25 @@
1
+ Pod::Spec.new do |s|
2
+ s.name = "GraniteScreen"
3
+ s.version = "1.0.0"
4
+ s.summary = "Screen management module for Granite framework"
5
+ s.description = "Provides GraniteViewController and related components for React Native integration"
6
+ s.homepage = "https://github.com/toss/brick"
7
+ s.license = { :type => "Apache-2.0", :file => "LICENSE" }
8
+ s.author = { "Toss" => "opensource@toss.im" }
9
+
10
+ s.platforms = { :ios => '13.0' }
11
+ s.source = { :path => "." }
12
+
13
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
14
+ s.public_header_files = "ios/**/*.h"
15
+ s.private_header_files = "ios/**/*+*.h"
16
+
17
+ s.pod_target_xcconfig = {
18
+ 'DEFINES_MODULE' => 'YES',
19
+ 'OTHER_SWIFT_FLAGS' => "-enable-experimental-feature AccessLevelOnImport"
20
+ }
21
+
22
+ s.dependency "ReactAppDependencyProvider"
23
+ add_dependency(s, "React-RCTAppDelegate")
24
+ install_modules_dependencies(s)
25
+ end
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but not
32
+ limited to compiled object code, generated documentation, and
33
+ conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the
44
+ purposes of this License, Derivative Works shall not include works
45
+ that remain separable from, or merely link (or bind by name) to the
46
+ interfaces of, the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,62 @@
1
+ project(granite-screen)
2
+ cmake_minimum_required(VERSION 3.9.0)
3
+
4
+ set(PACKAGE_NAME "granite-screen")
5
+ set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
6
+ set(CMAKE_VERBOSE_MAKEFILE ON)
7
+ set(CMAKE_CXX_STANDARD 17)
8
+
9
+ add_library(
10
+ ${PACKAGE_NAME}
11
+ SHARED
12
+ src/main/cpp/onLoad.cpp
13
+ src/main/cpp/BundleEvaluator.cpp
14
+ )
15
+
16
+ # Configure C++ 17
17
+ set_target_properties(
18
+ ${PACKAGE_NAME}
19
+ PROPERTIES
20
+ CXX_STANDARD 17
21
+ CXX_EXTENSIONS OFF
22
+ POSITION_INDEPENDENT_CODE ON
23
+ LINKER_LANGUAGE CXX
24
+ )
25
+
26
+
27
+ find_package(fbjni REQUIRED CONFIG)
28
+ find_package(ReactAndroid REQUIRED CONFIG)
29
+
30
+ target_include_directories(
31
+ ${PACKAGE_NAME}
32
+ PRIVATE
33
+ "src/main/cpp"
34
+ "${REACT_NATIVE_DIR}/ReactCommon"
35
+ "${REACT_NATIVE_DIR}/ReactCommon/callinvoker"
36
+ "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule"
37
+ )
38
+ # REACT_NATIVE_MERGED_SO is not set properly
39
+ # use version check instead
40
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
41
+ target_link_libraries(
42
+ ${PACKAGE_NAME}
43
+ ReactAndroid::reactnative
44
+ )
45
+ else()
46
+ target_link_libraries(
47
+ ${PACKAGE_NAME}
48
+ ReactAndroid::reactnativejni
49
+ )
50
+ endif()
51
+
52
+ target_link_libraries(
53
+ ${PACKAGE_NAME}
54
+ android
55
+ fbjni::fbjni
56
+ ReactAndroid::jsi
57
+ )
58
+
59
+ # Enable Android 16kb native library alignment
60
+ if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS "27")
61
+ target_link_options(${PACKAGE_NAME} PRIVATE "-Wl,-z,max-page-size=16384")
62
+ endif()
@@ -0,0 +1,63 @@
1
+ apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
3
+
4
+ android {
5
+ namespace "run.granite"
6
+ compileSdkVersion 35
7
+
8
+ sourceSets {
9
+ main {
10
+ manifest.srcFile 'src/main/AndroidManifest.xml'
11
+ }
12
+ }
13
+
14
+ defaultConfig {
15
+ minSdkVersion 24
16
+ targetSdkVersion 35
17
+ versionCode 1
18
+ versionName "1.0"
19
+
20
+ externalNativeBuild {
21
+ cmake {
22
+ arguments "-DANDROID_STL=c++_shared"
23
+ }
24
+ }
25
+ }
26
+
27
+ buildFeatures {
28
+ buildConfig true
29
+ prefab true
30
+ }
31
+
32
+ externalNativeBuild {
33
+ cmake {
34
+ path "CMakeLists.txt"
35
+ }
36
+ }
37
+
38
+ buildTypes {
39
+ release {
40
+ minifyEnabled false
41
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
42
+ }
43
+ }
44
+
45
+ compileOptions {
46
+ sourceCompatibility JavaVersion.VERSION_17
47
+ targetCompatibility JavaVersion.VERSION_17
48
+ }
49
+
50
+ kotlinOptions {
51
+ jvmTarget = '17'
52
+ }
53
+ }
54
+
55
+ dependencies {
56
+ api 'com.facebook.react:react-android:+'
57
+ implementation 'com.facebook.fbjni:fbjni:+'
58
+ implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22'
59
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
60
+ implementation 'com.google.code.gson:gson:2.8.9'
61
+ implementation 'androidx.annotation:annotation:1.5.0'
62
+ implementation project(':brick-module')
63
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,27 @@
1
+ #include "BundleEvaluator.h"
2
+ #include <fbjni/fbjni.h>
3
+
4
+ void BundleEvaluator::registerNatives() {
5
+ registerHybrid(
6
+ {makeNativeMethod("evaluateJavascriptSync", BundleEvaluator::evaluateJavascriptSync)});
7
+ }
8
+
9
+ void BundleEvaluator::evaluateJavascriptSync(
10
+ jni::alias_ref<jhybridobject> jThis,
11
+ jlong jsRuntime,
12
+ jni::alias_ref<JArrayByte> code,
13
+ jni::alias_ref<JString> url) {
14
+ auto pinnedCode = code->pin();
15
+ jbyte *sourcePtr = pinnedCode.get();
16
+ size_t sourceSize = pinnedCode.size();
17
+
18
+ // Use initializer list for source and sourceUrl
19
+ std::string source{reinterpret_cast<const char *>(sourcePtr), sourceSize};
20
+ std::string sourceUrl = url->toString();
21
+
22
+ if (jsRuntime == 0) {
23
+ return;
24
+ }
25
+ auto rt = reinterpret_cast<jsi::Runtime *>(jsRuntime);
26
+ rt->evaluateJavaScript(std::make_unique<jsi::StringBuffer>(std::move(source)), std::move(sourceUrl));
27
+ };
@@ -0,0 +1,17 @@
1
+ #include <fbjni/fbjni.h>
2
+ #include <jsi/jsi.h>
3
+
4
+ using namespace facebook;
5
+ using namespace facebook::jni;
6
+
7
+ struct BundleEvaluator : public jni::HybridClass<BundleEvaluator> {
8
+ static constexpr auto kJavaDescriptor = "Lrun/granite/BundleEvaluator;";
9
+
10
+ static void registerNatives();
11
+
12
+ static void evaluateJavascriptSync(
13
+ jni::alias_ref<jhybridobject> jThis,
14
+ jlong jsRuntime,
15
+ jni::alias_ref<JArrayByte> code,
16
+ jni::alias_ref<JString> url);
17
+ };
@@ -0,0 +1,6 @@
1
+ #include <fbjni/fbjni.h>
2
+ #include "BundleEvaluator.h"
3
+
4
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
5
+ return facebook::jni::initialize(vm, [] { BundleEvaluator::registerNatives(); });
6
+ }
@@ -0,0 +1,50 @@
1
+ package run.granite
2
+
3
+ import com.facebook.react.bridge.ReactContext
4
+ import com.facebook.react.common.annotations.FrameworkAPI
5
+
6
+ @OptIn(FrameworkAPI::class)
7
+ class BundleEvaluator(
8
+ private val reactContext: ReactContext,
9
+ ) {
10
+ private external fun evaluateJavascriptSync(
11
+ jsRuntime: Long,
12
+ code: ByteArray,
13
+ url: String,
14
+ )
15
+
16
+ fun evaluate(
17
+ script: ByteArray,
18
+ url: String,
19
+ ) {
20
+ val jsRuntime =
21
+ reactContext.javaScriptContextHolder?.get()
22
+ ?: throw IllegalStateException("javaScriptContextHolder is null.")
23
+
24
+ evaluateJavascriptSync(jsRuntime, script, url)
25
+ }
26
+
27
+ companion object {
28
+ init {
29
+ // Loads the native granite-screen library containing the JNI evaluateJavascriptSync method.
30
+ // WARNING: This will throw UnsatisfiedLinkError if the native library is not available
31
+ // (e.g., in unit tests without native dependencies). Use Robolectric or mock this class
32
+ // in unit test environments.
33
+ System.loadLibrary("granite-screen")
34
+ }
35
+
36
+ /**
37
+ * Convenience method to evaluate JavaScript on the JSI runtime.
38
+ * @param scriptData The JavaScript code as a byte array
39
+ * @param url The source URL for error reporting
40
+ * @param reactContext The React context containing the JSI runtime
41
+ */
42
+ fun evaluate(
43
+ scriptData: ByteArray,
44
+ url: String,
45
+ reactContext: ReactContext,
46
+ ) {
47
+ BundleEvaluator(reactContext).evaluate(scriptData, url)
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,40 @@
1
+ package run.granite
2
+
3
+ /**
4
+ * Interface for loading React Native bundles from various sources Implementations can provide
5
+ * different loading strategies (CDN, local, etc.)
6
+ */
7
+ interface BundleLoader {
8
+ /** Load a bundle and return the source information. */
9
+ suspend fun loadBundle(): BundleSource
10
+ }
11
+
12
+ /** Represents the source of a React Native bundle */
13
+ sealed class BundleSource {
14
+ /** The React component name registered via AppRegistry.registerComponent(). */
15
+ abstract val componentName: String?
16
+
17
+ /** Development mode: Bundle served from Metro bundler */
18
+ data class DevServer(
19
+ val host: String = "localhost",
20
+ val port: Int = 8081,
21
+ override val componentName: String? = null,
22
+ ) : BundleSource()
23
+
24
+ /** Production mode: Bundle from CDN or APK */
25
+ data class Production(
26
+ val location: ProductionLocation,
27
+ override val componentName: String? = null,
28
+ ) : BundleSource()
29
+ }
30
+
31
+ /** Represents the location of a production bundle */
32
+ sealed class ProductionLocation {
33
+ /** @param path Local file path after download */
34
+ data class FileSystemBundle(
35
+ val filePath: String,
36
+ ) : ProductionLocation()
37
+
38
+ /** Bundle embedded in APK assets */
39
+ data object EmbeddedBundle : ProductionLocation()
40
+ }
@@ -0,0 +1,20 @@
1
+ package run.granite
2
+
3
+ /**
4
+ * Default BundleLoader implementation matching the iOS example.
5
+ * - DEBUG: loads from Metro dev server (localhost:8081)
6
+ * - RELEASE: uses embedded APK asset bundle
7
+ */
8
+ class DefaultBundleLoader(
9
+ private val moduleName: String,
10
+ ) : BundleLoader {
11
+ override suspend fun loadBundle(): BundleSource =
12
+ if (BuildConfig.DEBUG) {
13
+ BundleSource.DevServer(host = "localhost", port = 8081, componentName = moduleName)
14
+ } else {
15
+ BundleSource.Production(
16
+ location = ProductionLocation.EmbeddedBundle,
17
+ componentName = moduleName,
18
+ )
19
+ }
20
+ }
@@ -0,0 +1,58 @@
1
+ package run.granite
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.view.Gravity
6
+ import android.widget.FrameLayout
7
+ import android.widget.ScrollView
8
+ import android.widget.TextView
9
+
10
+ /**
11
+ * Default error view displayed when React Native bundle loading fails Shows the error message in a
12
+ * scrollable view
13
+ */
14
+ class DefaultErrorView(
15
+ context: Context,
16
+ error: Throwable,
17
+ ) : FrameLayout(context) {
18
+ init {
19
+ // Set white background
20
+ setBackgroundColor(Color.WHITE)
21
+
22
+ // Create scroll view for long error messages
23
+ val scrollView = ScrollView(context)
24
+
25
+ // Create error text view
26
+ val errorTextView =
27
+ TextView(context).apply {
28
+ text =
29
+ buildString {
30
+ appendLine("Failed to load React Native bundle")
31
+ appendLine()
32
+ appendLine("Error: ${error.message ?: error.javaClass.simpleName}")
33
+
34
+ // Add stack trace in debug builds
35
+ if (BuildConfig.DEBUG) {
36
+ appendLine()
37
+ appendLine("Stack trace:")
38
+ error.stackTraceToString().lines().take(10).forEach { line ->
39
+ appendLine(line)
40
+ }
41
+ }
42
+ }
43
+ textSize = 14f
44
+ setTextColor(Color.rgb(220, 38, 38)) // Red color
45
+ setPadding(32, 32, 32, 32)
46
+ }
47
+
48
+ scrollView.addView(errorTextView)
49
+
50
+ val params =
51
+ LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT).apply {
52
+ gravity = Gravity.CENTER
53
+ setMargins(16, 16, 16, 16)
54
+ }
55
+
56
+ addView(scrollView, params)
57
+ }
58
+ }
@@ -0,0 +1,51 @@
1
+ package run.granite
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.view.Gravity
6
+ import android.widget.FrameLayout
7
+ import android.widget.ProgressBar
8
+ import android.widget.TextView
9
+
10
+ /**
11
+ * Default loading view displayed while React Native bundle is loading Shows a progress indicator
12
+ * and loading message
13
+ */
14
+ class DefaultLoadingView(
15
+ context: Context,
16
+ ) : FrameLayout(context) {
17
+ init {
18
+ // Set white background
19
+ setBackgroundColor(Color.WHITE)
20
+
21
+ // Create and add progress indicator
22
+ val progressBar = ProgressBar(context).apply { isIndeterminate = true }
23
+
24
+ val progressParams =
25
+ LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT).apply {
26
+ gravity = Gravity.CENTER
27
+ }
28
+
29
+ addView(progressBar, progressParams)
30
+
31
+ // Create and add loading text
32
+ val loadingText =
33
+ TextView(context).apply {
34
+ text = DEFAULT_LOADING_TEXT
35
+ textSize = 16f
36
+ setTextColor(Color.GRAY)
37
+ }
38
+
39
+ val textParams =
40
+ LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT).apply {
41
+ gravity = Gravity.CENTER
42
+ topMargin = 120 // Place below progress bar
43
+ }
44
+
45
+ addView(loadingText, textParams)
46
+ }
47
+
48
+ companion object {
49
+ private const val DEFAULT_LOADING_TEXT = "Loading..."
50
+ }
51
+ }