|
| 1 | +import type { LibrariesResult } from './NativeReactNativeLegal'; |
| 2 | + |
| 3 | +export const ReactNativeLegal = { |
| 4 | + getLibrariesAsync: () => { |
| 5 | + const payload = require(`react-native-legal/.rnlegal/libraries.json`); |
| 6 | + |
| 7 | + return Promise.resolve<LibrariesResult>({ |
| 8 | + data: payload.map((library: any) => ({ |
| 9 | + id: library.packageKey, |
| 10 | + name: library.packageKey, |
| 11 | + licenses: [{ licenseContent: library.content }], |
| 12 | + })), |
| 13 | + }); |
| 14 | + }, |
| 15 | + launchLicenseListScreen: (licenseHeaderText?: string) => { |
| 16 | + const payload = require(`react-native-legal/.rnlegal/libraries.json`); |
| 17 | + |
| 18 | + const main = document.createElement('main'); |
| 19 | + |
| 20 | + main.style.display = 'flex'; |
| 21 | + main.style.alignSelf = 'stretch'; |
| 22 | + main.style.flex = '1'; |
| 23 | + main.style.flexDirection = 'column'; |
| 24 | + main.style.overflow = 'scroll'; |
| 25 | + main.style.width = '100%'; |
| 26 | + |
| 27 | + const closeBtn = document.createElement('button'); |
| 28 | + |
| 29 | + closeBtn.innerText = 'Close'; |
| 30 | + |
| 31 | + const headerContainer = document.createElement('header'); |
| 32 | + |
| 33 | + headerContainer.style.display = 'flex'; |
| 34 | + headerContainer.style.flexDirection = 'row'; |
| 35 | + headerContainer.style.alignItems = 'center'; |
| 36 | + headerContainer.style.justifyContent = 'space-between'; |
| 37 | + headerContainer.appendChild(closeBtn); |
| 38 | + |
| 39 | + main.appendChild(headerContainer); |
| 40 | + |
| 41 | + if (licenseHeaderText) { |
| 42 | + const header = document.createElement('h1'); |
| 43 | + |
| 44 | + header.innerText = licenseHeaderText; |
| 45 | + |
| 46 | + headerContainer.insertBefore(header, closeBtn); |
| 47 | + } else { |
| 48 | + headerContainer.style.flexDirection = 'row-reverse'; |
| 49 | + } |
| 50 | + |
| 51 | + payload.forEach((library: any) => { |
| 52 | + const summary = document.createElement('summary'); |
| 53 | + |
| 54 | + summary.style.fontSize = '20px'; |
| 55 | + summary.style.margin = '10px 0px'; |
| 56 | + summary.innerText = library.packageKey; |
| 57 | + |
| 58 | + const content = document.createElement('p'); |
| 59 | + |
| 60 | + content.innerText = library.content; |
| 61 | + |
| 62 | + const details = document.createElement('details'); |
| 63 | + |
| 64 | + details.appendChild(summary); |
| 65 | + details.appendChild(content); |
| 66 | + |
| 67 | + main.appendChild(details); |
| 68 | + }); |
| 69 | + |
| 70 | + const dialog = document.createElement('dialog'); |
| 71 | + |
| 72 | + dialog.id = 'react-native-legal-dialog'; |
| 73 | + dialog.style.height = '90%'; |
| 74 | + dialog.style.width = '90%'; |
| 75 | + dialog.appendChild(main); |
| 76 | + |
| 77 | + document.querySelector('body')?.appendChild(dialog); |
| 78 | + |
| 79 | + closeBtn.addEventListener( |
| 80 | + 'click', |
| 81 | + () => { |
| 82 | + document.querySelector('body')?.removeChild(dialog); |
| 83 | + }, |
| 84 | + { once: true }, |
| 85 | + ); |
| 86 | + dialog.addEventListener( |
| 87 | + 'close', |
| 88 | + () => { |
| 89 | + document.querySelector('body')?.removeChild(dialog); |
| 90 | + }, |
| 91 | + { once: true }, |
| 92 | + ); |
| 93 | + dialog.showModal(); |
| 94 | + }, |
| 95 | +}; |
0 commit comments