Skip to content

Commit

Permalink
chore: project refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Jun 12, 2023
1 parent fca430b commit bd73adf
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 21 deletions.
84 changes: 72 additions & 12 deletions packages/ui-document-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@
* [Vue](#vue)
* [Examples](#examples)
* [Demos and Development](#demos-and-development)
* [Setup](#setup)
* [Repo Setup](#repo-setup)
* [Build](#build)
* [Demos](#demos)
* [Contributing](#contributing)
* [Update repo ](#update-repo-)
* [Update readme ](#update-readme-)
* [Update doc ](#update-doc-)
* [Publish](#publish)
* [modifying submodules](#modifying-submodules)
* [Questions](#questions)


Expand Down Expand Up @@ -93,18 +99,18 @@ export function openFilePicker(params: FilePickerOptions): Promise<{ files: stri
## Demos and Development


### Setup

To run the demos, you must clone this repo **recursively**.
### Repo Setup

The repo uses submodules. If you did not clone with ` --recursive` then you need to call
```
git clone https://github.com/@nativescript-community/ui-document-picker.git --recursive
git submodule update --init
```

**Install Dependencies:**
```bash
npm i # or 'yarn install' or 'pnpm install'
```
The package manager used to install and link dependencies must be `pnpm` or `yarn`. `npm` wont work.

To develop and test:
if you use `yarn` then run `yarn`
if you use `pnpm` then run `pnpm i`

**Interactive Menu:**

Expand All @@ -113,10 +119,9 @@ To start the interactive menu, run `npm start` (or `yarn start` or `pnpm start`)
### Build

```bash
npm run build

npm run build.angular # or for Angular
npm run build.all
```
WARNING: it seems `yarn build.all` wont always work (not finding binaries in `node_modules/.bin`) which is why the doc explicitly uses `npm run`

### Demos

Expand All @@ -125,6 +130,61 @@ npm run demo.[ng|react|svelte|vue].[ios|android]

npm run demo.svelte.ios # Example
```

Demo setup is a bit special in the sense that if you want to modify/add demos you dont work directly in `demo-[ng|react|svelte|vue]`
Instead you work in `demo-snippets/[ng|react|svelte|vue]`
You can start from the `install.ts` of each flavor to see how to register new demos


[](#contributing)

## Contributing

### Update repo

You can update the repo files quite easily

First update the submodules

```bash
npm run update
```

Then commit the changes
Then update common files

```bash
npm run sync
```
Then you can run `yarn|pnpm`, commit changed files if any

### Update readme
```bash
npm run readme
```

### Update doc
```bash
npm run doc
```

### Publish

The publishing is completely handled by `lerna` (you can add `-- --bump major` to force a major release)
Simply run
```shell
npm run publish
```

### modifying submodules

The repo uses https:// for submodules which means you won't be able to push directly into the submodules.
One easy solution is t modify `~/.gitconfig` and add
```
[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
```


[](#questions)

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-document-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
"license": "Apache-2.0",
"readmeFilename": "README.md",
"dependencies": {
"@nativescript-community/perms": "2.2.5"
"@nativescript-community/perms": "^2.3.0"
}
}
2 changes: 1 addition & 1 deletion packages/ui-document-picker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"tns-core-modules/*": ["./node_modules/@nativescript/core/*"]
}
},
"include": ["../../src/ui-document-picker/**/*.ts", "../../references.d.ts", "../../src/references.d.ts"],
"include": ["../../src/ui-document-picker/**/*.ts", "../../references.d.ts", "../../tools/references.d.ts", "../../src/references.d.ts"],
"exclude": ["../../src/ui-document-picker/angular/**"]
}
11 changes: 5 additions & 6 deletions src/ui-document-picker/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { request } from '@nativescript-community/perms';
import { AndroidActivityResultEventData, android as androidApp } from '@nativescript/core/application';
import { AndroidApplication, Device } from '@nativescript/core';
import { AndroidActivityResultEventData, AndroidApplication, Application, Device } from '@nativescript/core';
import lazy from '@nativescript/core/utils/lazy';
import { CommonPickerOptions, FilePickerOptions, FolderPickerOptions } from './index.common';

Expand All @@ -16,10 +15,10 @@ async function callIntent(context, intent, pickerType) {
const onEvent = function (e: AndroidActivityResultEventData) {
if (e.requestCode === pickerType) {
resolve(e);
androidApp.off(AndroidApplication.activityResultEvent, onEvent);
Application.android.off(AndroidApplication.activityResultEvent, onEvent);
}
};
androidApp.once(AndroidApplication.activityResultEvent, onEvent);
Application.android.once(AndroidApplication.activityResultEvent, onEvent);
context.startActivityForResult(intent, pickerType);
});
}
Expand Down Expand Up @@ -63,7 +62,7 @@ function prepareIntent(intent: android.content.Intent, options: CommonPickerOpti
}

export function openFilePicker(params: FilePickerOptions = {}) {
const context = androidApp.foregroundActivity || androidApp.startActivity;
const context = Application.android.foregroundActivity || Application.android.startActivity;
const FILE_CODE = 1231;

if (!Intent) {
Expand Down Expand Up @@ -157,7 +156,7 @@ function updatePersistableUris(context: android.content.Context, uri: android.ne
}
}
export function pickFolder(params: FolderPickerOptions = {}) {
const context = androidApp.foregroundActivity || androidApp.startActivity;
const context = Application.android.foregroundActivity || Application.android.startActivity;
const FOLDER_CODE = 1232;
if (!Intent) {
Intent = android.content.Intent;
Expand Down
2 changes: 1 addition & 1 deletion src/ui-document-picker/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function openFilePicker(params: FilePickerOptions = {}) {
if (params.extensions && params.extensions.length > 0) {
documentTypes = Utils.ios.collections.jsArrayToNSArray(params.extensions);
} else {
documentTypes = Utils.ios.collections.jsArrayToNSArray([kUTTypeContent]);
documentTypes = Utils.ios.collections.jsArrayToNSArray([UTTypeContent.identifier]);
}

return new Promise((resolve, reject) => {
Expand Down
2 changes: 2 additions & 0 deletions src/ui-document-picker/references.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/// <reference path="./typings/android.d.ts" />
/// <reference path="../../node_modules/@nativescript/types-ios/lib/ios/objc-x86_64/objc!UIKit.d.ts" />
/// <reference path="../../node_modules/@nativescript/types-ios/lib/ios/objc-x86_64/objc!UniformTypeIdentifiers.d.ts" />

0 comments on commit bd73adf

Please sign in to comment.