react-native-legal 1.0.0-next.1
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.
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/ReactNativeLegal.podspec +46 -0
- package/android/build.gradle +75 -0
- package/android/react-native-helpers.gradle +45 -0
- package/android/src/main/java/com/reactnativelegal/ReactNativeLegalActivity.kt +98 -0
- package/android/src/main/java/com/reactnativelegal/ReactNativeLegalModuleImpl.kt +19 -0
- package/android/src/main/java/com/reactnativelegal/ReactNativeLegalTurboPackage.kt +38 -0
- package/android/src/main/res/layout/activity_licenses.xml +28 -0
- package/android/src/main/res/values/styles.xml +7 -0
- package/android/src/main/res/values-v29/styles.xml +8 -0
- package/android/src/newarch/java/com/reactnativelegal/ReactNativeLegalModule.kt +17 -0
- package/android/src/oldarch/java/com/reactnativelegal/ReactNativeLegalModule.kt +23 -0
- package/app.plugin.js +1 -0
- package/bare-plugin/build/android/addListActivity.d.ts +4 -0
- package/bare-plugin/build/android/addListActivity.js +22 -0
- package/bare-plugin/build/android/androidCommand.d.ts +7 -0
- package/bare-plugin/build/android/androidCommand.js +25 -0
- package/bare-plugin/build/android/applyAndConfigureAboutLibrariesPlugin.d.ts +6 -0
- package/bare-plugin/build/android/applyAndConfigureAboutLibrariesPlugin.js +27 -0
- package/bare-plugin/build/android/declareAboutLibrariesPlugin.d.ts +6 -0
- package/bare-plugin/build/android/declareAboutLibrariesPlugin.js +27 -0
- package/bare-plugin/build/android/utils.d.ts +14 -0
- package/bare-plugin/build/android/utils.js +37 -0
- package/bare-plugin/build/index.d.ts +2 -0
- package/bare-plugin/build/index.js +9 -0
- package/bare-plugin/build/ios/addSettingsBundle.d.ts +4 -0
- package/bare-plugin/build/ios/addSettingsBundle.js +27 -0
- package/bare-plugin/build/ios/iosCommand.d.ts +7 -0
- package/bare-plugin/build/ios/iosCommand.js +23 -0
- package/bare-plugin/build/ios/registerLicensePlistBuildPhase.d.ts +7 -0
- package/bare-plugin/build/ios/registerLicensePlistBuildPhase.js +24 -0
- package/bare-plugin/build/ios/utils.d.ts +33 -0
- package/bare-plugin/build/ios/utils.js +98 -0
- package/bare-plugin/src/android/addListActivity.ts +22 -0
- package/bare-plugin/src/android/androidCommand.ts +23 -0
- package/bare-plugin/src/android/applyAndConfigureAboutLibrariesPlugin.ts +21 -0
- package/bare-plugin/src/android/declareAboutLibrariesPlugin.ts +21 -0
- package/bare-plugin/src/android/utils.ts +34 -0
- package/bare-plugin/src/index.ts +9 -0
- package/bare-plugin/src/ios/addSettingsBundle.ts +27 -0
- package/bare-plugin/src/ios/iosCommand.ts +21 -0
- package/bare-plugin/src/ios/registerLicensePlistBuildPhase.ts +22 -0
- package/bare-plugin/src/ios/utils.ts +120 -0
- package/bare-plugin/tsconfig.json +20 -0
- package/ios/ReactNativeLegal-Bridging-Header.h +1 -0
- package/ios/ReactNativeLegalDetailViewController.swift +156 -0
- package/ios/ReactNativeLegalLicenseMetadata.swift +4 -0
- package/ios/ReactNativeLegalModule.h +7 -0
- package/ios/ReactNativeLegalModule.mm +29 -0
- package/ios/ReactNativeLegalModuleImpl.swift +78 -0
- package/ios/ReactNativeLegalTableViewController.swift +72 -0
- package/lib/commonjs/NativeReactNativeLegal.js +10 -0
- package/lib/commonjs/NativeReactNativeLegal.js.map +1 -0
- package/lib/commonjs/ReactNativeLegal.android.js +18 -0
- package/lib/commonjs/ReactNativeLegal.android.js.map +1 -0
- package/lib/commonjs/ReactNativeLegal.ios.js +18 -0
- package/lib/commonjs/ReactNativeLegal.ios.js.map +1 -0
- package/lib/commonjs/ReactNativeLegal.js +13 -0
- package/lib/commonjs/ReactNativeLegal.js.map +1 -0
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/NativeReactNativeLegal.js +3 -0
- package/lib/module/NativeReactNativeLegal.js.map +1 -0
- package/lib/module/ReactNativeLegal.android.js +10 -0
- package/lib/module/ReactNativeLegal.android.js.map +1 -0
- package/lib/module/ReactNativeLegal.ios.js +10 -0
- package/lib/module/ReactNativeLegal.ios.js.map +1 -0
- package/lib/module/ReactNativeLegal.js +6 -0
- package/lib/module/ReactNativeLegal.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/NativeReactNativeLegal.d.ts +7 -0
- package/lib/typescript/NativeReactNativeLegal.d.ts.map +1 -0
- package/lib/typescript/ReactNativeLegal.android.d.ts +4 -0
- package/lib/typescript/ReactNativeLegal.android.d.ts.map +1 -0
- package/lib/typescript/ReactNativeLegal.d.ts +4 -0
- package/lib/typescript/ReactNativeLegal.d.ts.map +1 -0
- package/lib/typescript/ReactNativeLegal.ios.d.ts +4 -0
- package/lib/typescript/ReactNativeLegal.ios.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +97 -0
- package/plugin/build/android/addListActivity.d.ts +5 -0
- package/plugin/build/android/addListActivity.js +17 -0
- package/plugin/build/android/applyAndConfigureAboutLibrariesPlugin.d.ts +7 -0
- package/plugin/build/android/applyAndConfigureAboutLibrariesPlugin.js +22 -0
- package/plugin/build/android/declareAboutLibrariesPlugin.d.ts +7 -0
- package/plugin/build/android/declareAboutLibrariesPlugin.js +22 -0
- package/plugin/build/android/withAndroidLegal.d.ts +8 -0
- package/plugin/build/android/withAndroidLegal.js +30 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +11 -0
- package/plugin/build/ios/addSettingsBundle.d.ts +5 -0
- package/plugin/build/ios/addSettingsBundle.js +28 -0
- package/plugin/build/ios/registerLicensePlistBuildPhase.d.ts +8 -0
- package/plugin/build/ios/registerLicensePlistBuildPhase.js +23 -0
- package/plugin/build/ios/withIosLegal.d.ts +8 -0
- package/plugin/build/ios/withIosLegal.js +28 -0
- package/plugin/jest.config.js +1 -0
- package/plugin/src/android/addListActivity.ts +19 -0
- package/plugin/src/android/applyAndConfigureAboutLibrariesPlugin.ts +23 -0
- package/plugin/src/android/declareAboutLibrariesPlugin.ts +21 -0
- package/plugin/src/android/withAndroidLegal.ts +28 -0
- package/plugin/src/index.ts +14 -0
- package/plugin/src/ios/addSettingsBundle.ts +29 -0
- package/plugin/src/ios/registerLicensePlistBuildPhase.ts +24 -0
- package/plugin/src/ios/withIosLegal.ts +26 -0
- package/plugin/tsconfig.json +9 -0
- package/plugin-utils/build/android.d.ts +12 -0
- package/plugin-utils/build/android.js +91 -0
- package/plugin-utils/build/common.d.ts +45 -0
- package/plugin-utils/build/common.js +312 -0
- package/plugin-utils/build/ios.d.ts +11 -0
- package/plugin-utils/build/ios.js +86 -0
- package/plugin-utils/src/android.ts +99 -0
- package/plugin-utils/src/common.ts +398 -0
- package/plugin-utils/src/ios.ts +102 -0
- package/plugin-utils/tsconfig.json +20 -0
- package/react-native.config.js +13 -0
- package/src/NativeReactNativeLegal.ts +8 -0
- package/src/ReactNativeLegal.android.ts +10 -0
- package/src/ReactNativeLegal.ios.ts +10 -0
- package/src/ReactNativeLegal.ts +5 -0
- package/src/index.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Callstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# `react-native-legal`
|
|
2
|
+
|
|
3
|
+
Automagically generate license acknowledgements for your React Native app 🚀
|
|
4
|
+
|
|
5
|
+
| Android | iOS | AndroidTV | tvOS |
|
|
6
|
+
| - | - | - | - |
|
|
7
|
+
|  |  |  |  |
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
yarn add react-native-legal
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm i --save react-native-legal
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
This tool is split into 2 parts:
|
|
24
|
+
- a library that lets you display native screen with a list of all dependencies and their licenses
|
|
25
|
+
- a [config plugin](https://docs.expo.dev/config-plugins/introduction/?redirected) (for Expo projects) and a [custom community cli plugin](https://github.com/react-native-community/cli/blob/main/docs/plugins.md) (for bare RN projects)
|
|
26
|
+
|
|
27
|
+
### I want to generate licenses in my Expo project <a name="usage-expo"></a>
|
|
28
|
+
|
|
29
|
+
1. Add the config plugin to the `app.json`/`app.config.js`
|
|
30
|
+
|
|
31
|
+
```diff
|
|
32
|
+
{
|
|
33
|
+
"expo": {
|
|
34
|
+
"plugins": [
|
|
35
|
+
+ "react-native-legal"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Use the library in the codebase
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import * as React from 'react';
|
|
45
|
+
import { Button, View } from 'react-native';
|
|
46
|
+
import { ReactNativeLegal } from 'react-native-legal';
|
|
47
|
+
|
|
48
|
+
function launchNotice() {
|
|
49
|
+
ReactNativeLegal.launchLicenseListScreen('OSS Notice');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function MyComponent() {
|
|
53
|
+
return (
|
|
54
|
+
<View>
|
|
55
|
+
<Button onPress={launchNotice} text="Open source licenses" />
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
3. Use [Prebuild](https://docs.expo.dev/workflow/prebuild/) or [EAS](https://docs.expo.dev/eas/) to build the app
|
|
62
|
+
|
|
63
|
+
### I want to generate licenses in my bare RN project <a name="usage-bare-rn"></a>
|
|
64
|
+
|
|
65
|
+
1. Invoke the CLI plugin from the root of your RN app
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
npx react-native legal-generate
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
or
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
yarn react-native legal-generate
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
2. Use the library in the codebase
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import * as React from 'react';
|
|
81
|
+
import { Button, View } from 'react-native';
|
|
82
|
+
import { ReactNativeLegal } from 'react-native-legal';
|
|
83
|
+
|
|
84
|
+
function launchNotice() {
|
|
85
|
+
ReactNativeLegal.launchLicenseListScreen('OSS Notice');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function MyComponent() {
|
|
89
|
+
return (
|
|
90
|
+
<View>
|
|
91
|
+
<Button onPress={launchNotice} text="Open source licenses" />
|
|
92
|
+
</View>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Expo
|
|
98
|
+
|
|
99
|
+
- ✅ You can use this library with [Development Builds](https://docs.expo.dev/development/introduction/) by adding `react-native-legal` to your `app.json`/`app.config.js` plugins array.
|
|
100
|
+
- ❌ This library can't be used in the "Expo Go" app because it [requires custom native code](https://docs.expo.dev/workflow/customizing/).
|
|
101
|
+
|
|
102
|
+
## Contributing
|
|
103
|
+
|
|
104
|
+
See the [contributing guide](./CONTRIBUTING) to learn how to contribute to the repository and the development workflow.
|
|
105
|
+
|
|
106
|
+
## Acknowledgements
|
|
107
|
+
|
|
108
|
+
- [AboutLibraries](https://github.com/mikepenz/AboutLibraries) - collects and displays the license metadata for the Android app <3
|
|
109
|
+
- [LicensePlist](https://github.com/mono0926/LicensePlist) - generates license metadata for the iOS app <3
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
|
|
6
|
+
|
|
7
|
+
Pod::Spec.new do |s|
|
|
8
|
+
s.name = "ReactNativeLegal"
|
|
9
|
+
s.version = package["version"]
|
|
10
|
+
s.summary = package["description"]
|
|
11
|
+
s.description = package["description"]
|
|
12
|
+
s.homepage = package["homepage"]
|
|
13
|
+
s.license = package["license"]
|
|
14
|
+
s.platforms = { :ios => "12.0", :tvos => "12.0" }
|
|
15
|
+
s.author = package["author"]
|
|
16
|
+
s.source = { :git => package["repository"]["url"], :tag => "#{s.version}" }
|
|
17
|
+
|
|
18
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
19
|
+
s.dependency 'LicensePlist'
|
|
20
|
+
|
|
21
|
+
if new_arch_enabled
|
|
22
|
+
s.pod_target_xcconfig = {
|
|
23
|
+
"DEFINES_MODULE" => "YES",
|
|
24
|
+
"SWIFT_OBJC_INTERFACE_HEADER_NAME" => "ReactNativeLegal-Swift.h",
|
|
25
|
+
# This is handy when we want to detect if new arch is enabled in Swift code
|
|
26
|
+
# and can be used like:
|
|
27
|
+
# #if REACT_NATIVE_LEGAL_NEW_ARCH_ENABLED
|
|
28
|
+
# // do sth when new arch is enabled
|
|
29
|
+
# #else
|
|
30
|
+
# // do sth when old arch is enabled
|
|
31
|
+
# #endif
|
|
32
|
+
"OTHER_SWIFT_FLAGS" => "-DREACT_NATIVE_LEGAL_NEW_ARCH_ENABLED"
|
|
33
|
+
}
|
|
34
|
+
else
|
|
35
|
+
s.pod_target_xcconfig = {
|
|
36
|
+
"DEFINES_MODULE" => "YES",
|
|
37
|
+
"SWIFT_OBJC_INTERFACE_HEADER_NAME" => "ReactNativeLegal-Swift.h"
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Install all React Native dependencies (RN >= 0.71 must be used)
|
|
42
|
+
#
|
|
43
|
+
# check source code for more context
|
|
44
|
+
# https://github.com/facebook/react-native/blob/0.71-stable/scripts/react_native_pods.rb#L172#L180
|
|
45
|
+
install_modules_dependencies(s)
|
|
46
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.safeExtGet = {prop, fallback ->
|
|
3
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
def kotlin_version = safeExtGet('kotlinVersion', '1.7.22')
|
|
7
|
+
|
|
8
|
+
repositories {
|
|
9
|
+
google()
|
|
10
|
+
gradlePluginPortal()
|
|
11
|
+
}
|
|
12
|
+
dependencies {
|
|
13
|
+
classpath("com.android.tools.build:gradle:7.2.1")
|
|
14
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
def isNewArchitectureEnabled() {
|
|
19
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
apply plugin: 'com.android.library'
|
|
23
|
+
apply plugin: 'kotlin-android'
|
|
24
|
+
if (isNewArchitectureEnabled()) {
|
|
25
|
+
apply plugin: "com.facebook.react"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 33)
|
|
30
|
+
|
|
31
|
+
namespace "com.reactnativelegal"
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion safeExtGet('minSdkVersion', 21)
|
|
35
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 33)
|
|
36
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
sourceSets {
|
|
40
|
+
main {
|
|
41
|
+
if (isNewArchitectureEnabled()) {
|
|
42
|
+
java.srcDirs += ['src/newarch/java', "${project.buildDir}/generated/source/codegen/java"]
|
|
43
|
+
} else {
|
|
44
|
+
java.srcDirs += ['src/oldarch/java']
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
repositories {
|
|
51
|
+
maven {
|
|
52
|
+
url "$projectDir/../node_modules/react-native/android"
|
|
53
|
+
}
|
|
54
|
+
mavenCentral()
|
|
55
|
+
google()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
apply from: "$projectDir/react-native-helpers.gradle"
|
|
59
|
+
|
|
60
|
+
dependencies {
|
|
61
|
+
if (project.ext.shouldConsumeReactNativeFromMavenCentral()) {
|
|
62
|
+
implementation "com.facebook.react:react-android" // Set by the React Native Gradle Plugin
|
|
63
|
+
} else {
|
|
64
|
+
implementation 'com.facebook.react:react-native:+' // From node_modules
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
def aboutLibrariesPluginVersion = "10.8.3"
|
|
68
|
+
implementation("com.mikepenz:aboutlibraries-core-android:$aboutLibrariesPluginVersion")
|
|
69
|
+
implementation("com.mikepenz:aboutlibraries:$aboutLibrariesPluginVersion") {
|
|
70
|
+
exclude group: 'com.mikepenz', module: 'aboutlibraries-core'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
def constraintLayoutVersion = "2.1.4"
|
|
74
|
+
implementation("androidx.constraintlayout:constraintlayout:$constraintLayoutVersion")
|
|
75
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
def safeAppExtGet(prop, fallback) {
|
|
2
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
3
|
+
appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Let's detect react-native's directory, it will be used to determine RN's version
|
|
7
|
+
// https://github.com/software-mansion/react-native-reanimated/blob/cda4627c3337c33674f05f755b7485165c6caca9/android/build.gradle#L88
|
|
8
|
+
def resolveReactNativeDirectory() {
|
|
9
|
+
def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
|
|
10
|
+
if (reactNativeLocation != null) {
|
|
11
|
+
return file(reactNativeLocation)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// monorepo workaround
|
|
15
|
+
// react-native can be hoisted or in project's own node_modules
|
|
16
|
+
def reactNativeFromNodeModules = file("${projectDir}/../../react-native")
|
|
17
|
+
if (reactNativeFromNodeModules.exists()) {
|
|
18
|
+
return reactNativeFromNodeModules
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def reactNativeFromProjectNodeModules = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
|
|
22
|
+
if (reactNativeFromProjectNodeModules.exists()) {
|
|
23
|
+
return reactNativeFromProjectNodeModules
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
throw new GradleException(
|
|
27
|
+
"[react-native-legal] Unable to resolve react-native location in " +
|
|
28
|
+
"node_modules. You should project extension property (in app/build.gradle) " +
|
|
29
|
+
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// https://github.com/software-mansion/react-native-reanimated/blob/cda4627c3337c33674f05f755b7485165c6caca9/android/build.gradle#L199#L205
|
|
34
|
+
def reactNativeRootDir = resolveReactNativeDirectory()
|
|
35
|
+
|
|
36
|
+
def reactProperties = new Properties()
|
|
37
|
+
print("$reactNativeRootDir")
|
|
38
|
+
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
39
|
+
|
|
40
|
+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
|
|
41
|
+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
42
|
+
|
|
43
|
+
project.ext.shouldConsumeReactNativeFromMavenCentral = { ->
|
|
44
|
+
return REACT_NATIVE_MINOR_VERSION >= 71
|
|
45
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
package com.reactnativelegal
|
|
2
|
+
|
|
3
|
+
import android.content.pm.PackageManager
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import android.view.MenuItem
|
|
6
|
+
import android.view.View
|
|
7
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
8
|
+
import androidx.appcompat.widget.Toolbar
|
|
9
|
+
import androidx.core.view.WindowInsetsCompat
|
|
10
|
+
import androidx.core.view.updatePadding
|
|
11
|
+
import com.mikepenz.aboutlibraries.LibsBuilder.Companion.BUNDLE_TITLE
|
|
12
|
+
import com.mikepenz.aboutlibraries.ui.LibsSupportFragment
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Based on AboutLibraries LibsActivity,
|
|
16
|
+
* but simplified (no search filter),
|
|
17
|
+
* with improved back handling
|
|
18
|
+
* and hidden Toolbar/ActionBar for TV devices
|
|
19
|
+
*/
|
|
20
|
+
class ReactNativeLegalActivity: AppCompatActivity() {
|
|
21
|
+
private lateinit var fragment: LibsSupportFragment
|
|
22
|
+
|
|
23
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
24
|
+
setTheme(R.style.ReactNativeLegalTheme)
|
|
25
|
+
super.onCreate(savedInstanceState)
|
|
26
|
+
setContentView(R.layout.activity_licenses)
|
|
27
|
+
|
|
28
|
+
val bundle = intent.extras
|
|
29
|
+
fragment = LibsSupportFragment().apply {
|
|
30
|
+
arguments = bundle
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// https://developer.android.com/training/tv/start/hardware.html#runtime-check
|
|
34
|
+
val isTVDevice = packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
|
|
35
|
+
|
|
36
|
+
if (isTVDevice) {
|
|
37
|
+
hideToolbar()
|
|
38
|
+
} else {
|
|
39
|
+
setupToolbar(bundle)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).commit()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
46
|
+
if (item.itemId == android.R.id.home) {
|
|
47
|
+
onBackPressedDispatcher.onBackPressed()
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return super.onOptionsItemSelected(item)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private fun hideToolbar() {
|
|
54
|
+
val toolbar = findViewById<Toolbar>(R.id.toolbar)
|
|
55
|
+
toolbar.visibility = View.GONE
|
|
56
|
+
supportActionBar?.hide()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private fun setupToolbar(bundle: Bundle?) {
|
|
60
|
+
val title = bundle?.let {
|
|
61
|
+
it.getString(BUNDLE_TITLE, "")
|
|
62
|
+
} ?: ""
|
|
63
|
+
|
|
64
|
+
val toolbar = findViewById<Toolbar>(R.id.toolbar)
|
|
65
|
+
setSupportActionBar(toolbar)
|
|
66
|
+
|
|
67
|
+
supportActionBar?.let {
|
|
68
|
+
it.setDisplayHomeAsUpEnabled(true)
|
|
69
|
+
it.setDisplayShowTitleEnabled(title.isNotEmpty())
|
|
70
|
+
it.title = title
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
toolbar.setOnApplyWindowInsetsListener { v, insets ->
|
|
74
|
+
val systemInsets = WindowInsetsCompat.toWindowInsetsCompat(insets)
|
|
75
|
+
.getInsets(WindowInsetsCompat.Type.systemBars())
|
|
76
|
+
v.updatePadding(
|
|
77
|
+
left = v.paddingLeft + systemInsets.left,
|
|
78
|
+
top = v.paddingTop + systemInsets.top,
|
|
79
|
+
right = v.paddingRight + systemInsets.right
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
insets
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (toolbar.isAttachedToWindow) {
|
|
86
|
+
toolbar.requestApplyInsets()
|
|
87
|
+
} else {
|
|
88
|
+
toolbar.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
|
89
|
+
override fun onViewAttachedToWindow(v: View) {
|
|
90
|
+
v.removeOnAttachStateChangeListener(this)
|
|
91
|
+
v.requestApplyInsets()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
override fun onViewDetachedFromWindow(v: View) = Unit
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.reactnativelegal
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.mikepenz.aboutlibraries.LibsBuilder
|
|
6
|
+
|
|
7
|
+
object ReactNativeLegalModuleImpl {
|
|
8
|
+
const val NAME = "ReactNativeLegalModule"
|
|
9
|
+
|
|
10
|
+
fun launchLicenseListScreen(reactContext: ReactApplicationContext, licenseHeaderText: String) {
|
|
11
|
+
val context = reactContext.currentActivity ?: return
|
|
12
|
+
val intent = Intent(context, ReactNativeLegalActivity::class.java).apply {
|
|
13
|
+
this.putExtra("data", LibsBuilder())
|
|
14
|
+
this.putExtra(LibsBuilder.BUNDLE_TITLE, licenseHeaderText)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
context.startActivity(intent)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package com.reactnativelegal
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.TurboReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
9
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule
|
|
10
|
+
|
|
11
|
+
class ReactNativeLegalTurboPackage: TurboReactPackage() {
|
|
12
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
13
|
+
return when (name) {
|
|
14
|
+
ReactNativeLegalModule.NAME -> ReactNativeLegalModule(reactContext)
|
|
15
|
+
else -> null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
20
|
+
val moduleList: Array<Class<out NativeModule?>> = arrayOf(
|
|
21
|
+
ReactNativeLegalModule::class.java
|
|
22
|
+
)
|
|
23
|
+
val reactModuleInfoMap: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
24
|
+
for (moduleClass in moduleList) {
|
|
25
|
+
val reactModule = moduleClass.getAnnotation(ReactModule::class.java) ?: continue
|
|
26
|
+
reactModuleInfoMap[reactModule.name] =
|
|
27
|
+
ReactModuleInfo(
|
|
28
|
+
reactModule.name,
|
|
29
|
+
moduleClass.name,
|
|
30
|
+
true,
|
|
31
|
+
reactModule.needsEagerInit,
|
|
32
|
+
reactModule.isCxxModule,
|
|
33
|
+
TurboModule::class.java.isAssignableFrom(moduleClass)
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
return ReactModuleInfoProvider { reactModuleInfoMap }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
4
|
+
android:layout_width="match_parent"
|
|
5
|
+
android:layout_height="match_parent">
|
|
6
|
+
|
|
7
|
+
<androidx.appcompat.widget.Toolbar
|
|
8
|
+
android:id="@+id/toolbar"
|
|
9
|
+
style="?toolbarStyle"
|
|
10
|
+
android:layout_width="0dp"
|
|
11
|
+
android:layout_height="wrap_content"
|
|
12
|
+
app:contentInsetStart="0dp"
|
|
13
|
+
app:contentInsetStartWithNavigation="0dp"
|
|
14
|
+
app:elevation="4dp"
|
|
15
|
+
app:layout_constraintEnd_toEndOf="parent"
|
|
16
|
+
app:layout_constraintStart_toStartOf="parent"
|
|
17
|
+
app:layout_constraintTop_toTopOf="parent" />
|
|
18
|
+
|
|
19
|
+
<androidx.fragment.app.FragmentContainerView
|
|
20
|
+
android:id="@+id/fragment_container"
|
|
21
|
+
android:layout_width="0dp"
|
|
22
|
+
android:layout_height="0dp"
|
|
23
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
|
24
|
+
app:layout_constraintEnd_toEndOf="parent"
|
|
25
|
+
app:layout_constraintStart_toStartOf="parent"
|
|
26
|
+
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
|
27
|
+
|
|
28
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<resources>
|
|
3
|
+
<style name="ReactNativeLegalTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
|
|
4
|
+
<item name="android:statusBarColor">#F3EFEE</item>
|
|
5
|
+
<item name="android:windowBackground">#F3EFEE</item>
|
|
6
|
+
</style>
|
|
7
|
+
</resources>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<resources>
|
|
3
|
+
<style name="ReactNativeLegalTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
|
|
4
|
+
<item name="android:statusBarColor">#F3EFEE</item>
|
|
5
|
+
<item name="android:windowBackground">#F3EFEE</item>
|
|
6
|
+
<item name="android:forceDarkAllowed">false</item>
|
|
7
|
+
</style>
|
|
8
|
+
</resources>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.reactnativelegal
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
5
|
+
|
|
6
|
+
@ReactModule(name = ReactNativeLegalModule.NAME)
|
|
7
|
+
class ReactNativeLegalModule(
|
|
8
|
+
reactContext: ReactApplicationContext
|
|
9
|
+
) : NativeReactNativeLegalSpec(reactContext) {
|
|
10
|
+
override fun launchLicenseListScreen(licenseHeaderText: String) {
|
|
11
|
+
ReactNativeLegalModuleImpl.launchLicenseListScreen(reactApplicationContext, licenseHeaderText)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
companion object {
|
|
15
|
+
const val NAME = ReactNativeLegalModuleImpl.NAME
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.reactnativelegal
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Promise
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
8
|
+
|
|
9
|
+
@ReactModule(name = ReactNativeLegalModule.NAME)
|
|
10
|
+
class ReactNativeLegalModule(
|
|
11
|
+
private val reactContext: ReactApplicationContext
|
|
12
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
13
|
+
override fun getName() = NAME
|
|
14
|
+
|
|
15
|
+
@ReactMethod
|
|
16
|
+
fun launchLicenseListScreen(licenseHeaderText: String) {
|
|
17
|
+
ReactNativeLegalModuleImpl.launchLicenseListScreen(reactApplicationContext, licenseHeaderText)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
companion object {
|
|
21
|
+
const val NAME = ReactNativeLegalModuleImpl.NAME
|
|
22
|
+
}
|
|
23
|
+
}
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./plugin/build');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addListActivity = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const android_1 = require("../../../plugin-utils/build/android");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Adds an Android Activity with list of dependencies and their licenses to project's AndroidManifest.xml
|
|
12
|
+
*/
|
|
13
|
+
async function addListActivity(androidProjectPath) {
|
|
14
|
+
const androidManifestPath = path_1.default.join(androidProjectPath, 'app', 'src', 'main', 'AndroidManifest.xml');
|
|
15
|
+
await (0, utils_1.modifyXMLFileContent)(androidManifestPath, (manifestObj) => {
|
|
16
|
+
if (manifestObj.manifest.application?.[0].activity) {
|
|
17
|
+
manifestObj.manifest.application[0].activity = (0, android_1.addListActivityUtil)(manifestObj.manifest.application?.[0].activity);
|
|
18
|
+
}
|
|
19
|
+
return manifestObj;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.addListActivity = addListActivity;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implementation of bare plugin's Android/Android TV setup
|
|
3
|
+
*
|
|
4
|
+
* It scans the NPM dependencies, generates AboutLibraries-compatible metadata for them,
|
|
5
|
+
* installs & configures AboutLibraries Gradle plugin and adds Android Activity with a list of dependencies and their licenses
|
|
6
|
+
*/
|
|
7
|
+
export declare function androidCommand(androidProjectPath: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.androidCommand = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const common_1 = require("../../../plugin-utils/build/common");
|
|
9
|
+
const addListActivity_1 = require("./addListActivity");
|
|
10
|
+
const applyAndConfigureAboutLibrariesPlugin_1 = require("./applyAndConfigureAboutLibrariesPlugin");
|
|
11
|
+
const declareAboutLibrariesPlugin_1 = require("./declareAboutLibrariesPlugin");
|
|
12
|
+
/**
|
|
13
|
+
* Implementation of bare plugin's Android/Android TV setup
|
|
14
|
+
*
|
|
15
|
+
* It scans the NPM dependencies, generates AboutLibraries-compatible metadata for them,
|
|
16
|
+
* installs & configures AboutLibraries Gradle plugin and adds Android Activity with a list of dependencies and their licenses
|
|
17
|
+
*/
|
|
18
|
+
function androidCommand(androidProjectPath) {
|
|
19
|
+
const licenses = (0, common_1.scanDependencies)(path_1.default.join(path_1.default.resolve(androidProjectPath, '..'), 'package.json'));
|
|
20
|
+
(0, common_1.generateAboutLibrariesNPMOutput)(licenses, androidProjectPath);
|
|
21
|
+
(0, declareAboutLibrariesPlugin_1.declareAboutLibrariesPlugin)(androidProjectPath);
|
|
22
|
+
(0, applyAndConfigureAboutLibrariesPlugin_1.applyAndConfigureAboutLibrariesPlugin)(androidProjectPath);
|
|
23
|
+
(0, addListActivity_1.addListActivity)(androidProjectPath);
|
|
24
|
+
}
|
|
25
|
+
exports.androidCommand = androidCommand;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyAndConfigureAboutLibrariesPlugin = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const android_1 = require("../../../plugin-utils/build/android");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
/**
|
|
12
|
+
* Modifies application's build.gradle with AboutLibraries plugin
|
|
13
|
+
*
|
|
14
|
+
* NOTE: As of now, it doesn't support build.gradle.kts (Gradle Kotlin Script)
|
|
15
|
+
*/
|
|
16
|
+
function applyAndConfigureAboutLibrariesPlugin(androidProjectPath) {
|
|
17
|
+
if (fs_1.default.existsSync(path_1.default.join(androidProjectPath, 'app', 'build.gradle.kts'))) {
|
|
18
|
+
console.warn('Gradle Kotlin scripts are not supported yet');
|
|
19
|
+
}
|
|
20
|
+
else if (fs_1.default.existsSync(path_1.default.join(androidProjectPath, 'app', 'build.gradle'))) {
|
|
21
|
+
(0, utils_1.modifyFileContent)(path_1.default.join(androidProjectPath, 'app', 'build.gradle'), android_1.applyAndConfigureAboutLibrariesPluginUtil);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
console.warn('Cannot find app/build.gradle file');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.applyAndConfigureAboutLibrariesPlugin = applyAndConfigureAboutLibrariesPlugin;
|