Skip to content

Commit 1e37d65

Browse files
authored
feat(#32): method that retrieves license metadata from native to JS (#33)
* feat(#32): methods for getting license metadata from native to JS * Create gorgeous-pillows-ring.md
1 parent b2b4353 commit 1e37d65

33 files changed

Lines changed: 619 additions & 131 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-legal": minor
3+
---
4+
5+
Method that retrieves license metadata from native to JS

.github/workflows/lint-swift.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
1212
jobs:
1313
lint-swift:
1414
name: Lint Swift
15-
runs-on: ubuntu-latest
15+
runs-on: macos-15
1616
steps:
1717
- name: Checkout Repo
1818
uses: actions/checkout@v4

.github/workflows/test-e2e-android.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
paths:
88
- '.github/workflows/test-e2e-android.yaml'
99
- 'examples/bare-example/e2e/checkLicenses/android.yaml'
10+
- 'examples/bare-example/e2e/checkLicenses/android-get-licenses.yaml'
1011
- 'packages/react-native-legal/**/*.[tj]sx?'
1112
- 'packages/react-native-legal/android/**'
1213
- 'packages/licenses-api/**/*.[tj]sx?'
@@ -34,7 +35,7 @@ jobs:
3435
strategy:
3536
fail-fast: false
3637
matrix:
37-
api-level: [30, 34, 35]
38+
api-level: [30, 35]
3839
steps:
3940
- name: Enable KVM group perms
4041
run: |

.github/workflows/test-e2e-ios.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
paths:
88
- '.github/workflows/test-e2e-ios.yaml'
99
- 'examples/bare-example/e2e/checkLicenses/ios.yaml'
10+
- 'examples/bare-example/e2e/checkLicenses/ios-get-licenses.yaml'
1011
- 'packages/react-native-legal/**/*.[tj]sx?'
1112
- 'packages/react-native-legal/ios/**'
1213
- 'packages/licenses-api/**/*.[tj]sx?'
@@ -34,7 +35,7 @@ jobs:
3435
strategy:
3536
fail-fast: false
3637
matrix:
37-
simulator: ['iPhone 16 Pro (18.5)', 'iPhone SE (3rd generation) (18.0)']
38+
simulator: ['iPhone 16 Pro (18.5)']
3839
steps:
3940
- name: Checkout Repo
4041
uses: actions/checkout@v4

docs/docs/docs/react-native.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ This will extract and prepare license metadata for use in your app.
5656

5757
## Usage
5858

59+
### Builtin list screen
60+
5961
Once the setup is complete, you can easily add a button to your app to display the list of open-source licenses:
6062

6163
```tsx
@@ -78,6 +80,45 @@ function MyComponent() {
7880

7981
This will open a native screen listing all detected licenses. The title of the screen can be customized by passing a different string argument to `launchLicenseListScreen()`.
8082

83+
### Retrieving licenses metadata and custom UI
84+
85+
If you want to handle the UI yourself, you can get the licenses metadata and display it with your custom UI:
86+
87+
```tsx
88+
import * as React from 'react';
89+
import { FlatList, Text, View } from 'react-native';
90+
import type { Library } from 'react-native-legal';
91+
import { ReactNativeLegal } from 'react-native-legal';
92+
93+
function keyExtractor(item: Library) {
94+
return item.id;
95+
}
96+
97+
function renderItem({ item }: ListRenderItemInfo<Library>) {
98+
return <Text>{item.name}</Text>;
99+
}
100+
101+
function MyComponent() {
102+
const [libraries, setLibraries] = React.useState<Library[]>([]);
103+
104+
React.useEffect(() => {
105+
async function getLibraries() {
106+
const result = = await ReactNativeLegal.getLibrariesAsync();
107+
108+
setLibraries(result.data);
109+
}
110+
111+
getLibraries();
112+
}, []);
113+
114+
return (
115+
<View>
116+
<FlatList data={libraries} keyExtractor={keyExtractor} renderItem={renderItem} />
117+
</View>
118+
);
119+
}
120+
```
121+
81122
## License Display in Settings <Badge text="iOS" type="info" />
82123

83124
On **iOS**, all detected licenses will also appear in the **Settings app** under the app's information section. This is done to comply with **Apple's guidelines**, which require apps to provide open-source license acknowledgments in a visible location.

examples/bare-example/App.tsx

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,19 @@
1-
import { Platform, Pressable, StatusBar, StyleSheet, Text, View } from 'react-native';
2-
import { ReactNativeLegal } from 'react-native-legal';
3-
4-
const BUTTON_BACKGROUND_COLOR = '#8232ff';
5-
const BUTTON_FONT_COLOR = '#FFF';
6-
const BUTTON_RIPPLE_COLOR = '#8232ffba';
1+
import { StatusBar, StyleSheet, View } from 'react-native';
2+
import { MainScreen } from 'react-native-legal-common-example-ui';
73

84
export default function App() {
9-
function launchNotice() {
10-
ReactNativeLegal.launchLicenseListScreen('OSS Notice');
11-
}
12-
135
return (
146
<View style={styles.container}>
15-
<Pressable
16-
accessibilityRole="button"
17-
android_ripple={{
18-
color: BUTTON_RIPPLE_COLOR,
19-
foreground: true,
20-
}}
21-
onPress={launchNotice}
22-
style={({ pressed }) => [styles.button, pressed && styles.pressed]}
23-
>
24-
<Text style={styles.label}>Tap to see list of OSS libraries</Text>
25-
</Pressable>
7+
<MainScreen />
268
<StatusBar backgroundColor="transparent" barStyle="dark-content" translucent />
279
</View>
2810
);
2911
}
3012

3113
const styles = StyleSheet.create({
32-
button: {
33-
backgroundColor: BUTTON_BACKGROUND_COLOR,
34-
borderRadius: 20,
35-
overflow: 'hidden',
36-
padding: 20,
37-
},
3814
container: {
3915
flex: 1,
4016
alignItems: 'center',
4117
justifyContent: 'center',
4218
},
43-
label: {
44-
color: BUTTON_FONT_COLOR,
45-
fontSize: 20,
46-
},
47-
pressed: {
48-
opacity: Platform.select({
49-
android: 1,
50-
default: 0.4,
51-
}),
52-
},
5319
});

examples/bare-example/android/app/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,3 @@ dependencies {
124124
}
125125

126126
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
127-
128-
aboutLibraries {
129-
configPath = "config"
130-
prettyPrint = true
131-
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
appId: com.reactnativelegalbareexample
2+
name: '[Android] Check React Native entry in custom OSS libraries list'
3+
tags:
4+
- pull-request
5+
- android
6+
---
7+
- launchApp:
8+
clearState: true
9+
stopApp: true
10+
- startRecording: 'e2e_results/checkLicenses-getLicences'
11+
- tapOn: 'Tap to get list of licenses'
12+
- assertVisible: 'EXIT LIST'
13+
# workaround for long list issue taking ages to scroll to 'r*' packages (causing a timeout)
14+
- repeat:
15+
times: 3
16+
commands:
17+
- swipe:
18+
start: 50%, 90%
19+
end: 50%, 0%
20+
duration: 50
21+
- scrollUntilVisible:
22+
element:
23+
containsChild: 'react-native'
24+
index: 0
25+
direction: 'DOWN'
26+
timeout: 190000
27+
centerElement: true
28+
speed: 70
29+
visibilityPercentage: 75
30+
- takeScreenshot: 'e2e_results/getLicenses-react-native_list_element'
31+
- assertVisible:
32+
text: 'react-native'
33+
index: 0
34+
- tapOn:
35+
text: 'react-native'
36+
index: 0
37+
- takeScreenshot: 'e2e_results/getLicenses-license_modal'
38+
- assertVisible: 'EXIT DETAIL VIEW'
39+
- assertVisible: '.*MIT License.*'
40+
- assertVisible: '.*Copyright \(c\).*'
41+
- assertVisible: '.*Permission is hereby granted, free of charge.*'
42+
- tapOn: 'EXIT DETAIL VIEW'
43+
- takeScreenshot: 'e2e_results/getLicenses-react-native_back_to_list'
44+
- assertVisible: 'EXIT LIST'
45+
- tapOn: 'EXIT LIST'
46+
- stopRecording
47+
- killApp
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
appId: org.reactjs.native.example.ReactNativeLegalBareExample
2+
name: '[iOS] Check React Native entry in custom OSS libraries list'
3+
tags:
4+
- pull-request
5+
- ios
6+
---
7+
- launchApp:
8+
clearState: true
9+
stopApp: true
10+
- startRecording: 'e2e_results/checkLicenses-getLicences'
11+
- tapOn: 'Tap to get list of licenses'
12+
- assertVisible: 'Exit list'
13+
# workaround for long list issue taking ages to scroll to 'r*' packages (causing a timeout)
14+
- repeat:
15+
times: 6
16+
commands:
17+
- swipe:
18+
start: 50%, 95%
19+
end: 50%, 0%
20+
duration: 50
21+
- scrollUntilVisible:
22+
label: Scroll to React Native library
23+
element: 'react-native (.*)'
24+
direction: 'DOWN'
25+
timeout: 100000
26+
speed: 80
27+
visibilityPercentage: 75
28+
- takeScreenshot: 'e2e_results/getLicenses-react-native_list_element'
29+
- tapOn: 'react-native (.*)'
30+
- takeScreenshot: 'e2e_results/getLicenses-react-native_entry'
31+
- assertVisible: 'Exit detail view'
32+
- assertVisible: 'react-native (.*)'
33+
- assertVisible: '.*MIT License.*'
34+
- tapOn: 'Exit detail view'
35+
- takeScreenshot: 'e2e_results/react-native_back_to_list'
36+
- assertVisible: 'Exit list'
37+
- tapOn: 'Exit list'
38+
- stopRecording
39+
- killApp

examples/bare-example/ios/Podfile.lock

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ PODS:
15101510
- React-logger (= 0.76.7)
15111511
- React-perflogger (= 0.76.7)
15121512
- React-utils (= 0.76.7)
1513-
- ReactNativeLegal (1.0.0):
1513+
- ReactNativeLegal (1.3.1):
15141514
- DoubleConversion
15151515
- glog
15161516
- hermes-engine
@@ -1747,66 +1747,66 @@ SPEC CHECKSUMS:
17471747
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
17481748
hermes-engine: eb4a80f6bf578536c58a44198ec93a30f6e69218
17491749
LicensePlist: c02e376f57ac50686b1f8bd825c2b9e727fe5fd3
1750-
RCT-Folly: bf5c0376ffe4dd2cf438dcf86db385df9fdce648
1750+
RCT-Folly: 84578c8756030547307e4572ab1947de1685c599
17511751
RCTDeprecation: 7691283dd69fed46f6653d376de6fa83aaad774c
17521752
RCTRequired: eac044a04629288f272ee6706e31f81f3a2b4bfe
17531753
RCTTypeSafety: cfe499e127eda6dd46e5080e12d80d0bfe667228
17541754
React: 1f3737a983fdd26fb3d388ddbca41a26950fe929
17551755
React-callinvoker: 5c15ac628eab5468fe0b4dc453495f4742761f00
1756-
React-Core: 4b90a977a5b2777fd8f4a8db7325a83431ecd2d8
1757-
React-CoreModules: 385bbacfa34ac9208aa24f239a5184fa7ab1cd28
1758-
React-cxxreact: 3e09bcdf1f86b931b5e96bf5429d7c274a0ec168
1756+
React-Core: e467bf49f10da6fe92d915d2311cd0fd9bfbe052
1757+
React-CoreModules: 0299b3c0782edd3b37c8445ba07bf18ceb73812d
1758+
React-cxxreact: 54e253030b3b82b05575f19a1fb0e25c049f30ba
17591759
React-debug: 2086b55a5e55fb0abae58c42b8f280ebd708c956
1760-
React-defaultsnativemodule: 491e2541856e3580dae7f29d80754673a2134e48
1761-
React-domnativemodule: 4aaed5d5eef3da7d7d49b1f2ae8f422a4d7794b7
1762-
React-Fabric: 5b8373d1bd34bf269b13529a0ebee0643165ccf8
1763-
React-FabricComponents: 3f8528c3ed060464a120e161ffaef9307a88817b
1764-
React-FabricImage: 8efa4e206b1e5cf2e8e1e48fd345619c5c0484f4
1760+
React-defaultsnativemodule: f80f41ea8c1216917fd224b553291360e0e6a175
1761+
React-domnativemodule: b14aaaf4afbaa7e1dbc86ad78cbcc71eb59f1faf
1762+
React-Fabric: 409ce8a065374d737bdbc0fce506dcdda8f51e88
1763+
React-FabricComponents: bd5faafffd07e56cf217d5417e80ec29348c19d9
1764+
React-FabricImage: 04d01f3ecfed6121733613a5c794f684e81cb3fb
17651765
React-featureflags: 4503c901bf16b267b689e8a1aed24e951e0b091b
1766-
React-featureflagsnativemodule: 415168f5d23413fd0cc55ad98c41a3f3f135b2a7
1767-
React-graphics: c619a6e974baf9a7dbae8442944c7b7408391d46
1768-
React-hermes: 24bfc254f1ba83182d4936641898fe963af343fb
1769-
React-idlecallbacksnativemodule: 2c2e4c3f561a98c84a7a68c0d1f868b64ca5f839
1770-
React-ImageManager: ba9c89729be310413c610444a658fac505253d2c
1771-
React-jserrorhandler: bf16ea495377b22223bf93f3ef6d0711b9852613
1772-
React-jsi: ede7e8c96f997f8772871c82688cea53c1ffb148
1773-
React-jsiexecutor: fc9b287189ce800a92d5ab4e7291508eacaab451
1774-
React-jsinspector: fa5e8b22102b599c2bb2aeafebbf957a1ab836da
1775-
React-jsitracing: f38c15aeb910bafcf3ba2e24af8c92e6af4ce1d4
1776-
React-logger: f9d104eace4ce03d7d5ab96802069d9905082225
1777-
React-Mapbuffer: 23ffe602d0f5ca53b861ef8534cb8c63c4479671
1778-
React-microtasksnativemodule: 73fdf0c53b6d50d55de2d5bd9abfb8c006b043a4
1766+
React-featureflagsnativemodule: 79c980bfc96bcdcc9bd793d49fe75bbfb0e417ad
1767+
React-graphics: c2febdc940fb3ebdaef082d940b70254ef49c7a1
1768+
React-hermes: 91baa15c07e76b0768d6e10f4dac1c080a47eef4
1769+
React-idlecallbacksnativemodule: 5daef402290b91e54a884101b032186c03fa1827
1770+
React-ImageManager: b258354a48a92168edc41fdc0c14a4310cc4d576
1771+
React-jserrorhandler: 45d858315f6474dad3912aadb3f6595004dc5f4f
1772+
React-jsi: 87fa67556d7a82125bc77930bf973717fb726d14
1773+
React-jsiexecutor: 3a92052dd96cff1cd693fa3ef8d9738b1d05372a
1774+
React-jsinspector: 05aff7dd91b0685d351cdeb8c151c9f9ec97accd
1775+
React-jsitracing: 419fa21e8543f5a938b11b5a0bfc257b00dac7a5
1776+
React-logger: 5cad0c76d056809523289e589309012215a393b5
1777+
React-Mapbuffer: a381120aea722d2244d4e4b663a10d4c3b2d4e51
1778+
React-microtasksnativemodule: d9b946675010659cddd1c7611c074216579c8ad3
17791779
React-nativeconfig: 67fa7a63ea288cb5b1d0dd2deaf240405fec164f
1780-
React-NativeModulesApple: cbf1a34443e1f67b56344547f4b0af69e1c685ba
1781-
React-perflogger: f02ee21d98773121d77993b3c1a8be445840fae3
1782-
React-performancetimeline: 7021d68884291b649b4c39ecb71e0fd3a2e53a59
1780+
React-NativeModulesApple: 34b7a4d7441a4ee78d18109ff107c1ccf7c074a9
1781+
React-perflogger: d1149037ac466ad2141d4ae541ca16cb73b2343b
1782+
React-performancetimeline: 6b46b0a17727a3ec22ec4777d156d6b6efc4f8eb
17831783
React-RCTActionSheet: ad84d5a0bd1ad1782f0b78b280c6f329ad79a53a
1784-
React-RCTAnimation: 388460f7c124c76e337c6646738a83d6ea147095
1785-
React-RCTAppDelegate: 4661e2a44f7ce1033bf6f373f7d5368b11f5a2be
1786-
React-RCTBlob: 07cccbb74e22ce66745358799f6ab02a5bed2993
1787-
React-RCTFabric: 77ebcd07a3c1f3d4c2d2f67f69033a65d16a36a8
1788-
React-RCTImage: 8fbdae841ea1217c44f4c413bba2403134b83cd1
1789-
React-RCTLinking: c59bf8286ba2cc327b01bb524fb9c16446dc18bc
1790-
React-RCTNetwork: 2c137a0aaaed2cf4bb53aff82a2bb8c34f2fbeac
1791-
React-RCTSettings: 9fcd32c5b38af6421a3dd20cdd9ebf09df0a9a6d
1792-
React-RCTText: 5308618477fec454282809065bd121c2bd3dd5e1
1793-
React-RCTVibration: 7b2a186756b5c8e586e3e7948eed4432a93299c0
1784+
React-RCTAnimation: 64ed42bb43b33b0d861126f83048429606390903
1785+
React-RCTAppDelegate: de8150cd7e748bd7a98ffc05c88f21c668407ab4
1786+
React-RCTBlob: e74dfdbbfcd46d9d1eec3b3a0f045e655e3f7861
1787+
React-RCTFabric: bc0327e719fb12f969ac0e17485ba274b9c2c335
1788+
React-RCTImage: 1b6d8ad60f74a3cec4ee52e0ca55f1773afd03f4
1789+
React-RCTLinking: 88b2384d876346fbb16839a60c1d20830b2e95fe
1790+
React-RCTNetwork: 88aa473814e796d3a7bc6a0b51e7ae5749bdc243
1791+
React-RCTSettings: 0d73a1846aef87ef07c2026c186ea0d80602a130
1792+
React-RCTText: bfdb776f849156f895909ee999b4b5f2f9cf9a0b
1793+
React-RCTVibration: 81c8bbcc841ce5a7ae6e1bd2ec949b30e58d1fcf
17941794
React-rendererconsistency: 65d4692825fda4d9516924b68c29d0f28da3158c
1795-
React-rendererdebug: 0b97f49d44c91862e1576961faf6bde836ed4eb3
1795+
React-rendererdebug: ab3696594d3506acc22ecea4dd68ac258c529c2d
17961796
React-rncore: 6aca111c05a48c58189a005cb10a7b52780738dc
1797-
React-RuntimeApple: aa20633298595444bf2dfbc5246889b4f475b871
1798-
React-RuntimeCore: 8ac56cc6d82a1090f1d15d48b487c9a5a1d7d915
1797+
React-RuntimeApple: 5245e8cf30e417fe3e798ed991b938679656ab8f
1798+
React-RuntimeCore: c79d23b31aded614f4afeaac53f4da37c792c362
17991799
React-runtimeexecutor: 732038d7c356ba74132f1d16253a410621d3c2c1
1800-
React-RuntimeHermes: a695d944686adc97f85a1b34c31840a0a39e356c
1801-
React-runtimescheduler: 00666e100e35a13f28fb2fdab22817cf62bbd6a3
1800+
React-RuntimeHermes: b3b1d7fc42d74141a71ae23fedbc4e07e5a7fbd2
1801+
React-runtimescheduler: 6e804311c6c9512ffe7f4b68d012767b225c48a1
18021802
React-timing: c2915214b94a62bdf77d2965c31f76bc25b362a5
1803-
React-utils: 9f9a6a31d703b136eb1614d914c10a3c96b1e6dd
1804-
ReactCodegen: 5d7e2d2948a6629a51a59ebc99f620e2afb13ee5
1805-
ReactCommon: 04292c6f596181ebf755e7929d96d2148542b0e8
1806-
ReactNativeLegal: 3514fb143867dc60703a0a04af5d9c200c8ae83f
1803+
React-utils: 0342746d2cf989cf5e0d1b84c98cfa152edbdf3f
1804+
ReactCodegen: ca395237650513af628c32aa1eb8fd586c771b13
1805+
ReactCommon: 81e0744ee33adfd6d586141b927024f488bc49ea
1806+
ReactNativeLegal: 8f73754d2e2fe06d3ba76e129654e427f5f3d1d4
18071807
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
18081808
Yoga: 90d80701b27946c4b23461c00a7207f300a6ff71
18091809

18101810
PODFILE CHECKSUM: d8cf13800dea3fa1eb0928883853c6b37979b1d5
18111811

1812-
COCOAPODS: 1.15.2
1812+
COCOAPODS: 1.16.2

0 commit comments

Comments
 (0)