diff --git a/docz/docs/02-getting-started/02-example.mdx b/docz/docs/02-getting-started/02-example.mdx index 0df6cb4..8b69063 100644 --- a/docz/docs/02-getting-started/02-example.mdx +++ b/docz/docs/02-getting-started/02-example.mdx @@ -721,38 +721,30 @@ The Android demo has been tested in Windows 10 and in macOS. Test the app in the Android simulator: ```bash -npm run android +npx react-native start ``` +Once Metro is ready, it will display the commands: + +``` +r - reload the app +d - open developer menu +i - run on iOS +a - run on Android +``` + +Press `a` to run on android. + After clicking "Press to Export", the app will show an alert with the location -to the generated file. +to the generated file (`/data/user/0/com.sheetjspres/files/Presidents.xlsx`) -In the Android simulator, pulling the file requires additional steps. This -command will pull a Base64-encoded string from the simulator: +In the Android simulator, pulling the file requires additional steps: ```bash -adb exec-out run-as com.sheetjspres base64 files/Presidents.xlsx > pres.b64 +adb root +adb pull /data/user/0/com.sheetjspres/files/Presidents.xlsx Presidents.xlsx ``` -Decoding the file requires an OS-specific command: - - - - -```powershell -certutil -decode .\pres.b64 .\Presidents.xlsx -``` - - - - -```bash -base64 -D pres.b64 > Presidents.xlsx -``` - - - - This command generates `Presidents.xlsx` which can be opened. :::info Device Testing diff --git a/docz/docs/03-demos/05-mobile/02-nativescript.md b/docz/docs/03-demos/05-mobile/02-nativescript.md index c889f0d..a0a3c56 100644 --- a/docz/docs/03-demos/05-mobile/02-nativescript.md +++ b/docz/docs/03-demos/05-mobile/02-nativescript.md @@ -17,10 +17,15 @@ The "Complete Example" creates an app that looks like the screenshots below: +
iOSAndroid
![iOS screenshot](pathname:///mobile/nsios.png) + + +![Android screenshot](pathname:///mobile/nsand.png) +
## Integration Details @@ -63,7 +68,8 @@ const wb = read(ab); #### Writing data -`getFileAccess().writeBufferAsync` can write data: +`getFileAccess().writeBufferAsync` can write data. iOS supports `Uint8Array` +directly but Android requires a true array of numbers: ```ts import { getFileAccess } from '@nativescript/core'; @@ -75,15 +81,15 @@ const url = get_url_for_filename("SheetJSNS.xls"); const u8: Uint8Array = write(wb, { bookType: 'xls', type: 'binary' }); /* attempt to save Uint8Array to file */ -await getFileAccess().writeBufferAsync(url, u8); +await getFileAccess().writeBufferAsync(url, global.isAndroid ? (Array.from(u8) as any) : u8); ``` ## Demo :::note -This demo was tested on an Intel Mac on 2023 April 03. NativeScript version -(as verified with `ns --version`) is `8.5.1`. +This demo was tested on an Intel Mac on 2023 May 07. NativeScript version +(as verified with `ns --version`) is `8.5.3`. The iOS simulator runs iOS 16.2 on an iPhone 14 Pro Max. @@ -91,6 +97,8 @@ The iOS simulator runs iOS 16.2 on an iPhone 14 Pro Max. 0) Follow the official Environment Setup instructions +### Base Project + 1) Create a skeleton NativeScript + Angular app: ```bash @@ -262,7 +270,7 @@ Restart the app process and two buttons should show up at the top: const u8: Uint8Array = write(wb, { bookType: 'xls', type: 'buffer' }); /* attempt to save Uint8Array to file */ - await getFileAccess().writeBufferAsync(url, u8); + await getFileAccess().writeBufferAsync(url, global.isAndroid ? (Array.from(u8) as any) : u8); await Dialogs.alert(`Wrote to SheetJSNS.xls at ${url}`); } catch(e) { await Dialogs.alert(e.message); } // highlight-end @@ -296,3 +304,40 @@ Restart the app after saving the file. ![NativeScript Step 7](pathname:///mobile/nativescript7.png) +### Android + +Launch the app with `ns run android`. If the app does not automatically launch, +manually open the `SheetJSNS` app. + +The app can be tested with the following sequence in the simulator: + +- Tap "Export File". A dialog will print where the file was written. Typicaly +the URL is `/data/user/0/org.nativescript.SheetJSNS/files/SheetJSNS.xls` + +- Pull the file from the simulator: + +```bash +adb root +adb pull /data/user/0/org.nativescript.SheetJSNS/files/SheetJSNS.xls SheetJSNS.xls +``` + +- Open `SheetJSNS.xls` with a spreadsheet editor. + +After the header row, insert a row with cell A2 = 0, B2 = SheetJS, C2 = Library: + +``` +id | name | role + 0 | SheetJS | Library + 1 | Ter Stegen | Goalkeeper + 3 | Piqué | Defender +... +``` + +- Push the file back to the simulator: + +```bash +adb push SheetJSNS.xls /data/user/0/org.nativescript.SheetJSNS/files/SheetJSNS.xls +``` + +- Tap "Import File". A dialog will print the path of the file that was read. + The first item in the list will change. \ No newline at end of file diff --git a/docz/static/mobile/nsand.png b/docz/static/mobile/nsand.png new file mode 100644 index 0000000..f91197f Binary files /dev/null and b/docz/static/mobile/nsand.png differ