Skip to content

Commit 1fbae55

Browse files
committed
feat(#112): properly support version field in "getLibrariesAsync" function
1 parent 84fc168 commit 1fbae55

5 files changed

Lines changed: 34 additions & 5 deletions

File tree

examples/bare-example/e2e/checkLicenses/ios-get-licenses.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ tags:
1515
end: 50%, 0%
1616
- scrollUntilVisible:
1717
label: Scroll to React Native library
18-
element: '@react-native/virtualized-lists (.*)'
18+
element: '@react-native/virtualized-lists'
1919
direction: 'DOWN'
2020
timeout: 60000
2121
speed: 80
2222
visibilityPercentage: 75
2323
- takeScreenshot: 'e2e_results/getLicenses-react-native_list_element'
24-
- tapOn: '@react-native/virtualized-lists (.*)'
24+
- tapOn: '@react-native/virtualized-lists'
2525
- takeScreenshot: 'e2e_results/getLicenses-react-native_entry'
2626
- assertVisible: 'Exit detail view'
27-
- assertVisible: '@react-native/virtualized-lists (.*)'
27+
- assertVisible: '@react-native/virtualized-lists'
2828
- assertVisible: '.*MIT.*'
2929
- tapOn: 'Exit detail view'
3030
- takeScreenshot: 'e2e_results/react-native_back_to_list'

examples/common-ui/src/CustomListDetails.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const CustomListDetails = ({ item, onModalClose }: Props) => {
1212
<Button onPress={onModalClose} title="Exit detail view" />
1313
<ScrollView style={styles.scroll}>
1414
<Text style={styles.header}>{item.name}</Text>
15+
{item.version ? <Text style={styles.subheader}>Version: {item.version}</Text> : null}
1516
<Text style={styles.content}>
1617
{item.licenses.map((license) => license.licenseContent).reduce((a, c) => a + '\n' + c, '')}
1718
</Text>
@@ -36,6 +37,11 @@ const styles = StyleSheet.create({
3637
fontWeight: 'bold',
3738
margin: 8,
3839
},
40+
subheader: {
41+
fontSize: 20,
42+
fontWeight: 'semibold',
43+
margin: 4,
44+
},
3945
scroll: {
4046
alignSelf: 'stretch',
4147
margin: 16,

packages/react-native-legal/android/src/main/java/com/reactnativelegal/ReactNativeLegalModuleImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ object ReactNativeLegalModuleImpl {
4444
bundleOf(
4545
"id" to library.uniqueId,
4646
"name" to library.name,
47+
"version" to library.artifactVersion,
4748
"description" to library.description,
4849
"website" to library.website,
4950
"developers" to library.developers.joinToString(),

packages/react-native-legal/ios/ReactNativeLegalModuleImpl.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,35 @@ public class ReactNativeLegalModuleImpl: NSObject {
4949

5050
return [
5151
"data": libraries.map({ library in
52-
[
53-
"id": "library-\(library.name ?? "")", "name": library.name ?? "",
52+
let (name, version) = splitNameAndVersion(library.name)
53+
return [
54+
"id": "library-\(library.name ?? "")",
55+
"name": name ?? "",
56+
"version": version as Any,
5457
"licenses": [["licenseContent": library.content ?? ""]],
5558
]
5659
})
5760
]
5861
}
5962

63+
private static func splitNameAndVersion(_ nameAndVersionStr: String?) -> (
64+
name: String?, version: String?
65+
) {
66+
guard let nameAndVersion = nameAndVersionStr else {
67+
return (nil, nil)
68+
}
69+
var elements = nameAndVersion.split(separator: " ")
70+
if elements.count <= 1 {
71+
return (nameAndVersion, nil)
72+
}
73+
var version = elements.removeLast()
74+
version.removeFirst() // remove "("
75+
version.removeLast() // remove ")"
76+
let name = elements.joined(separator: " ")
77+
78+
return (name, String(version))
79+
}
80+
6081
private static func getChildPaneSpecifiers(dictArray: [[String: Any]]) -> [[String: Any]] {
6182
return
6283
dictArray

packages/react-native-legal/src/NativeReactNativeLegal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface Library {
2121
id: string;
2222
name: string;
2323
licenses: License[];
24+
version?: string;
2425
/**
2526
* @platform Android
2627
*/

0 commit comments

Comments
 (0)