Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-buses-stop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-legal': 'minor'
---

Support `version` field in `Library` type returned via `getLibrariesAsync` function
6 changes: 3 additions & 3 deletions examples/bare-example/e2e/checkLicenses/ios-get-licenses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ tags:
end: 50%, 0%
- scrollUntilVisible:
label: Scroll to React Native library
element: '@react-native/virtualized-lists (.*)'
element: '@react-native/virtualized-lists'
direction: 'DOWN'
timeout: 60000
speed: 80
visibilityPercentage: 75
- takeScreenshot: 'e2e_results/getLicenses-react-native_list_element'
- tapOn: '@react-native/virtualized-lists (.*)'
- tapOn: '@react-native/virtualized-lists'
- takeScreenshot: 'e2e_results/getLicenses-react-native_entry'
- assertVisible: 'Exit detail view'
- assertVisible: '@react-native/virtualized-lists (.*)'
- assertVisible: '@react-native/virtualized-lists'
- assertVisible: '.*MIT.*'
- tapOn: 'Exit detail view'
- takeScreenshot: 'e2e_results/react-native_back_to_list'
Expand Down
6 changes: 6 additions & 0 deletions examples/common-ui/src/CustomListDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const CustomListDetails = ({ item, onModalClose }: Props) => {
<Button onPress={onModalClose} title="Exit detail view" />
<ScrollView style={styles.scroll}>
<Text style={styles.header}>{item.name}</Text>
{item.version ? <Text style={styles.subheader}>Version: {item.version}</Text> : null}
<Text style={styles.content}>
{item.licenses.map((license) => license.licenseContent).reduce((a, c) => a + '\n' + c, '')}
</Text>
Expand All @@ -36,6 +37,11 @@ const styles = StyleSheet.create({
fontWeight: 'bold',
margin: 8,
},
subheader: {
fontSize: 20,
fontWeight: 'semibold',
margin: 4,
},
scroll: {
alignSelf: 'stretch',
margin: 16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object ReactNativeLegalModuleImpl {
bundleOf(
"id" to library.uniqueId,
"name" to library.name,
"version" to library.artifactVersion,
"description" to library.description,
"website" to library.website,
"developers" to library.developers.joinToString(),
Expand Down
25 changes: 23 additions & 2 deletions packages/react-native-legal/ios/ReactNativeLegalModuleImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,35 @@ public class ReactNativeLegalModuleImpl: NSObject {

return [
"data": libraries.map({ library in
[
"id": "library-\(library.name ?? "")", "name": library.name ?? "",
let (name, version) = splitNameAndVersion(library.name)
return [
"id": "library-\(library.name ?? "")",
"name": name ?? "",
"version": version as Any,
"licenses": [["licenseContent": library.content ?? ""]],
]
})
]
}

private static func splitNameAndVersion(_ nameAndVersionStr: String?) -> (
name: String?, version: String?
) {
guard let nameAndVersion = nameAndVersionStr else {
return (nil, nil)
}
var elements = nameAndVersion.split(separator: " ")
if elements.count <= 1 {
return (nameAndVersion, nil)
}
var version = elements.removeLast()
version.removeFirst() // remove "("
version.removeLast() // remove ")"
let name = elements.joined(separator: " ")

return (name, String(version))
}

private static func getChildPaneSpecifiers(dictArray: [[String: Any]]) -> [[String: Any]] {
return
dictArray
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-legal/src/NativeReactNativeLegal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface Library {
id: string;
name: string;
licenses: License[];
version?: string;
/**
* @platform Android
*/
Expand Down
Loading