Skip to content

Commit

Permalink
Update Redme
Browse files Browse the repository at this point in the history
  • Loading branch information
Girish Parate authored and Girish Parate committed Feb 11, 2023
1 parent c153109 commit 01f171d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,63 @@ file dowload

## Installation

### npm

```sh
npm install react-native-ios-files-app-save
```

### yarn

```sh
yarn add react-native-ios-files-app-save
```

### Android AndroidManifest.xml

```sh
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
```

### iOS info.plist

```sh
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
```

## Usage

```js
import { multiply } from 'react-native-ios-files-app-save';
import { stateDownloadAppSave } from 'react-native-ios-files-app-save';

// ...
export default function App() {
const demoDownload = () => {
if (!hasPermission) {
//* Handle Permission
return;
}
stateDownloadAppSave('https://YOUFDF.COM/FILE/BILL/OCT.pdf')
.then((res: any) => {
console.log(res);
})
.catch((e) => {
console.log('error', e);
});
};

const result = await multiply(3, 7);
return (
<View style={styles.container}>
<Text onPress={demoDownload}>{'Start Download'}</Text>
</View>
);
}
```

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
Expand Down
25 changes: 8 additions & 17 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import * as React from 'react';

import { StyleSheet, View, Text } from 'react-native';
import { multiply, startDownload } from 'react-native-ios-files-app-save';
import { stateDownloadAppSave } from 'react-native-ios-files-app-save';

export default function App() {
console.log({ startDownload });

const [result, setResult] = React.useState<number | undefined>();

React.useEffect(() => {
multiply(3, 7).then(setResult);
}, []);

const runPackage = async () => {
try {
startDownload("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf").then((res: any) => {
console.log(res)
});
} catch (e) {
console.log(e)
}
const demoDownload = () => {
stateDownloadAppSave("https://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf").then((res: any) => {
console.log(res);
}).catch((e) => {
console.log("error", e);
})
}

return (
<View style={styles.container}>
<Text onPress={runPackage}>{"Start Download"}</Text>
<Text onPress={demoDownload}>{"Start Download"}</Text>
</View>
);
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "react-native-ios-files-app-save",
"version": "0.1.0",
"type": "module",
"description": "test",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
12 changes: 12 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ export const startDownload = async (url: string) => {
});
} catch (e) {
}
}

export const stateDownloadAppSave = (url: string) => {
return new Promise((resolve, reject) => {
try {
NativeModules.IosFilesAppSave.startDownload(url).then((res: any) => {
resolve(res)
});
} catch (e) {
reject(e)
}
});
}

0 comments on commit 01f171d

Please sign in to comment.