From 89e4a2a724ce136ddda66c1e805e08f0dc2a64f7 Mon Sep 17 00:00:00 2001 From: killi8n Date: Wed, 4 Nov 2020 18:59:35 +0900 Subject: [PATCH] feat: updated example --- example/src/App.tsx | 33 ++++++++++++++++++++++++++------- src/index.tsx | 20 +++++++++++++++++++- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index ad983cf..46331ed 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -2,8 +2,27 @@ import * as React from 'react'; import { StyleSheet, Button, SafeAreaView, Image, Text } from 'react-native'; import ImageSelector, { ImageSelectorCallbackResponse, + ImageSelectorOptions, } from 'react-native-image-selector'; +const options: ImageSelectorOptions = { + // import Options + storageOptions: { + skipBackup: true, + path: 'hello', + }, + permissionDenied: { + title: '권한 설정', + text: "이 기능을 이용하시려면 권한을 '허용'으로 변경해주세요.", + reTryTitle: '변경하러가기', + okTitle: '닫기', + }, + title: '사진 선택', + cancelButtonTitle: '취소', + takePhotoButtonTitle: '사진 촬영', + chooseFromLibraryButtonTitle: '앨범에서 가져오기', +}; + export default function App() { const [ response, @@ -11,15 +30,15 @@ export default function App() { ] = React.useState(null); const handlePhotos = async () => { try { - ImageSelector.launchPicker( - (error, response: ImageSelectorCallbackResponse) => { - if (error) { - console.log(error); - return; - } + ImageSelector.launchPicker(options, (error, response) => { + if (error) { + console.log(error); + return; + } + if (response) { setResponse(response); } - ); + }); } catch (e) { console.error(e); } diff --git a/src/index.tsx b/src/index.tsx index fe77e31..e4e8e09 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -9,11 +9,29 @@ export interface ImageSelectorCallbackResponse { path: string; } +export interface ImageSelectorOptions { + title?: string; + cancelButtonTitle?: string; + takePhotoButtonTitle?: string; + chooseFromLibraryButtonTitle?: string; + storageOptions?: { + skipBackup?: boolean; + path?: string; + }; + permissionDenied?: { + title?: string; + text?: string; + reTryTitle?: string; + okTitle?: string; + }; +} + type ImageSelectorType = { launchPicker: ( + options: ImageSelectorOptions, callback: ( error: { error: string }, - response: ImageSelectorCallbackResponse + response?: ImageSelectorCallbackResponse ) => void ) => void; };