Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
feat: added ImageSelectorCallbackResponse interface
Browse files Browse the repository at this point in the history
  • Loading branch information
killi8n committed Nov 4, 2020
1 parent 7b8b62e commit 786067c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
33 changes: 25 additions & 8 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import * as React from 'react';
import { StyleSheet, Button, SafeAreaView } from 'react-native';
import ImageSelector from 'react-native-image-selector';
import { StyleSheet, Button, SafeAreaView, Image } from 'react-native';
import ImageSelector, {
ImageSelectorCallbackResponse,
} from 'react-native-image-selector';

export default function App() {
const [
response,
setResponse,
] = React.useState<ImageSelectorCallbackResponse | null>(null);
const handlePhotos = async () => {
try {
ImageSelector.launchPicker((error, response) => {
if (error) {
console.log(error);
return;
ImageSelector.launchPicker(
(error, response: ImageSelectorCallbackResponse) => {
if (error) {
console.log(error);
return;
}
console.log(response);
setResponse(response);
}
console.log(response);
});
);
} catch (e) {
console.error(e);
}
Expand All @@ -20,6 +29,14 @@ export default function App() {
return (
<SafeAreaView style={styles.container}>
<Button title="GET USER PHOTOS" onPress={handlePhotos} />
{response !== null && (
<Image
style={{ width: 150, height: 150 }}
source={{
uri: response.uri,
}}
/>
)}
</SafeAreaView>
);
}
Expand Down
14 changes: 8 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { NativeModules } from 'react-native';

export interface ImageSelectorCallbackResponse {
fileSize: number;
fileName: string;
type: string;
uri: string;
}

type ImageSelectorType = {
launchPicker: (
callback: (
error: { error: string },
response: {
fileSize: number;
fileName: string;
type: string;
uri: string;
}
response: ImageSelectorCallbackResponse
) => void
) => void;
};
Expand Down

0 comments on commit 786067c

Please sign in to comment.