@supportworks/multi-imagepicker 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+
2
+ # @supportworks/Multi-ImagePicker
3
+
4
+ This library is used to implement react-native-image-crop-picker in iOS and Android apps built with react-native >= 0.60, which allows selection of multiple images at once.
5
+
6
+ ## Getting started
7
+
8
+ See 'peerDependencies' list in package.json. Make sure to install all of those libraries, or add them to your app's package.json.
9
+
10
+ Run `npm install @supportworks/Multi-ImagePicker` or add it to your package.json
11
+
12
+ NOTE: version 3.0 has breaking changes, is only for react-native >= 0.60.0, so be sure to use 'react-native-image-crop-picker' version >=0.25.0 instead of the older '@supportworks/react-native-image-crop-picker'. No other changes besides this should be needed to the code.
13
+
14
+ iOS: When building app the first time, in XCode, Under 'Embedded Binaries', add RSKImageCropper.framework and QBImagePicker.framework.
15
+
16
+ ## Usage - import
17
+ ```javascript
18
+ import {AddImages, MultiImagePicker} from '@supportworks/Multi-ImagePicker';
19
+ ```
20
+
21
+ ## Info.plist additions needed to add photos to Camera Roll for iOS
22
+ ## (Saving to CameraRoll only works for iOS currently):
23
+ ```javascript
24
+ <key>NSPhotoLibraryAddUsageDescription</key>
25
+ <string>We allow you to save photos into your media library that were taken within the app.</string>
26
+ <key>NSPhotoLibraryUsageDescription</key>
27
+ <string>We access your media library to let you upload pictures you already took to your appointments.</string>
28
+ ```
29
+
30
+
31
+ ## Usage - JSX Component Examples
32
+ There are 3 pieces to this library, of which one or more can be used.
33
+
34
+ 1: AddImages - used to easily add a button/icon/link to your app that allows you to select multiple images, with custom titles and descriptions, per image. This option eliminatres the need to use the Multi-ImagePicker option below.
35
+ ```javascript
36
+ onImagesAdded() {
37
+ //callback from MultiImagePicker, after images added
38
+ let cRef = this;
39
+
40
+ if (cRef.props.callback) {
41
+ cRef.props.callback("photos added");
42
+ }
43
+ }
44
+
45
+ render() {
46
+ ...
47
+ <AddImages parentStyle={styles.AddPhoto} prospectInst={Project} addPicture={Api.addOnePictureToProject} callback={cRef.onImagesAdded}>
48
+ <View style={styles.AddPhotoIcon}>
49
+ <Icons.IconCameraFill width="24" height="24" fill={colors.blue} fillOpacity="1" />
50
+ </View>
51
+ </AddImages>
52
+ ...
53
+ }
54
+ ```
55
+ 2: Multi-Image Picker - this allows you to select multiple images and return the results in arrays. The child you include (AddButton in this example) should display an icon that will be touched to open the picker. Note that your child component will be wrapped with a TouchableOpacity component, so any props you supply for MultiImagePicker will be passed to that TouchableOpacity component.
56
+ ```javascript
57
+ onImageSelect(payload) {
58
+ //handle return of selected images from MultiImagePicker
59
+ //payload expected (json): {index: integer, cancelIndex: integer, imageArray: [image info], imageDescArray: [image descriptions], imageValidArray: [array of true booleans], callbackData: any}
60
+
61
+ let cRef = this;
62
+
63
+ cRef.imgArr = payload.imageArray;
64
+ cRef.imgDescArr = payload.imageDescArray;
65
+ cRef.imgValidArr = payload.imageValidArray;
66
+ cRef.setState({showAdd: true});
67
+ }
68
+
69
+ render() {
70
+ ...
71
+ <MultiImagePicker callback={cRef.onImageSelect}>
72
+ <AddButton/>
73
+ </MultiImagePicker>
74
+ ...
75
+ }
76
+ ```
77
+ 3: Selected Image component - this allows you to display the images that were selected, before saving them, so you can edit their titles and descriptions.
78
+ ```javascript
79
+ setAllImageDataValid(allValid) {
80
+ //handle return of selected images from MultiImagePicker <SelectedImages>
81
+ //payload expected: (boolean) true if all selected images are valid, false otherwise
82
+ let cRef = this;
83
+ let initAllValid = cRef.state.allImageDataValid;
84
+ if (allValid !== initAllValid) {
85
+ //need to set state since overall validity flipped
86
+ cRef.setState({allImageDataValid: allValid});
87
+ }
88
+ }
89
+
90
+ render() {
91
+ ...
92
+ <KeyboardAwareScrollView>
93
+ <SelectedImages imgArr={cRef.imgArr} imgDescArr={cRef.imgDescArr} imgValidArr={cRef.imgValidArr} callback={cRef.setAllImageDataValid}/>
94
+ </KeyboardAwareScrollView>
95
+ ...
96
+ }
97
+ ```
package/changes.md ADDED
@@ -0,0 +1,90 @@
1
+
2
+ # v5.0.1 2023-08-09
3
+ * updated for RN71+: replaced react-native-image-resizer with @bam.tech/react-native-image-resizer
4
+
5
+ # v5.0.0 2023-07-27
6
+ * switched from deprecated @react-native-communiy/camera-roll version to @react-native-camera-roll/camera-roll
7
+ * the switch is required for react-native 0.71+
8
+
9
+ # v4.0.13 2023-05-29
10
+ * Changed project to history for invoking Canvas
11
+
12
+ # v4.0.12 2023-03-30
13
+ * Loops on camera
14
+
15
+ # v4.0.11 2022-08-20
16
+ * Change Resize Image
17
+
18
+ # v4.0.10 2022-07-09
19
+ * SingleImage update
20
+
21
+ # v4.0.9 2022-07-09
22
+ * SingleImage update
23
+
24
+ # v4.0.8 2022-06-17
25
+ * cache busting for images on android
26
+
27
+ # v4.0.7 2022-06-15
28
+ * reduce main image in pickerDone
29
+
30
+ # v4.0.6 2022-06-02
31
+ * save print reduced image
32
+
33
+ # v4.0.5 2022-05-24
34
+ * changed canvas color
35
+
36
+ # v4.0.4 2022-05-22
37
+ * called get/set canvas settings
38
+
39
+ # v4.0.3 2022-05-20
40
+ * changed save behavior
41
+
42
+ # v4.0.2 2022-05-20
43
+ * added support for annotation
44
+
45
+ # v4.0.1 2022-05-09
46
+ * added @react-native-community/blur to peerDependencies
47
+
48
+ # v4.0.0 2022-05-09
49
+ * replaced react-native-actionsheet library with @alessiocancian/react-native-actionsheet to remove deprecation warnings
50
+
51
+ # v3.0.10 2022-03-31
52
+ * whoops
53
+
54
+ # v3.0.9 2022-03-31
55
+ * don't show canvas for now
56
+
57
+ # v3.0.8 2022-03-13
58
+ * allowed for some label props to be passed into multiimagepicker
59
+
60
+ # v3.0.7 2021-02-26
61
+ * synced up with RN59 v2.2.3 changes, just added defaultProps to SingleImage
62
+
63
+ # v3.0.6 2021-02-26
64
+ * if there is a defaultName, it will be disabled/not editable unless you pass defaultOnly=false
65
+ * added check to use props.imgObject.defaultName for default image filename if it exists in the data
66
+
67
+ # v3.0.5 2022-01-23
68
+ * switched movelocalfile to movecopyfile
69
+
70
+ # v3.0.4 2022-01-22
71
+ * added canvas
72
+
73
+ # v3.0.2 2021-12-27
74
+ * converted to use api-core
75
+ * synced up with RN59 v2.2.0 changes
76
+
77
+ # v3.0.1 2021-12-23
78
+ * Copied over changes from v2.1.2 version, as noted below
79
+ * added checkbox with AsyncStorage to allow user control saving to camera roll
80
+ * added MIPickerApi, used only within library
81
+ * made CameraRoll.save() only applicable for iOS, since the camera roll library not ready for Android yet, awaiting that
82
+ * added CameraRoll.save() to save taken photos to device's photo library
83
+ * changed spinner in AddImages
84
+
85
+ # v3.0.0 2021-03-02
86
+ * Moved form SVN to Git with this release so that we could keep previous versions available for RN <0.60 without having to revert code.
87
+ * BREAKING CHANGE, so upped major version
88
+ * changed '@supportworks/react-native-image-crop-picker' to 'react-native-image-crop-picker' since no longer need our private version with RN60+
89
+ * Make the same update to package.json of apps, and any other referecnes to the old library name, to avoid breaking change, before using this version
90
+ * Use older v2.0 version for react-native <0.60
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import MultiImagePicker from './src/components/MultiImagePicker';
2
+ import SelectedImages from './src/components/SelectedImages';
3
+ import AddImages from "./src/components/AddImages";
4
+ import MIPickerApi from "./src/lib/MIPickerApi";
5
+
6
+ export {
7
+ MultiImagePicker,
8
+ SelectedImages,
9
+ AddImages,
10
+ MIPickerApi
11
+ };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@supportworks/multi-imagepicker",
3
+ "version": "5.0.1",
4
+ "description": "Android and iOS customized multiple image picker. For react-native >= 0.60.",
5
+ "main": "index.js",
6
+ "author": {
7
+ "name": "Ryan Case",
8
+ "email": "rcase@supportworks.com"
9
+ },
10
+ "peerDependencies": {
11
+ "@bam.tech/react-native-image-resizer": ">=3.0.5",
12
+ "react-native": ">=0.60.0",
13
+ "@alessiocancian/react-native-actionsheet": ">=3.1.2",
14
+ "@react-native-async-storage/async-storage": "^1.15.5",
15
+ "@react-native-community/blur": ">=3.6.0",
16
+ "@react-native-camera-roll/camera-roll": ">=5.7.2",
17
+ "@supportworks/api-core": ">=1.0.9",
18
+ "@supportworks/app-styler": ">=1.0.6",
19
+ "@supportworks/core-controls": ">=1.1.6",
20
+ "@supportworks/icon-library": ">=1.4.3",
21
+ "@supportworks/navbars": ">=0.1.3",
22
+ "@supportworks/SWMaterialDesign": ">=1.1.3",
23
+ "react-native-image-crop-picker": ">=0.25.0",
24
+ "react-native-responsive-layout": "git@github.com:InspiredAgency/react-native-responsive-layout.git",
25
+ "moment": ">=2.24.0"
26
+ }
27
+ }
@@ -0,0 +1,334 @@
1
+ import * as React from 'react';
2
+ import {
3
+ Text,
4
+ View,
5
+ Modal,
6
+ SafeAreaView,
7
+ TouchableOpacity,
8
+ StyleSheet, ScrollView, KeyboardAvoidingView, Platform, PermissionsAndroid
9
+ } from 'react-native';
10
+ import {Icons} from "@supportworks/icon-library";
11
+ import loaderHandler from './loaderHandler';
12
+ import MultiImagePicker from "./MultiImagePicker";
13
+ import SelectedImages from "./SelectedImages";
14
+ import AppStyler, {colors, stdStyles} from "@supportworks/app-styler";
15
+ import {LoadingOverlay} from '@supportworks/navbars';
16
+ import {CheckBox} from "@supportworks/core-controls";
17
+ import {CameraRoll} from "@react-native-camera-roll/camera-roll";
18
+ import {Api} from '@supportworks/api-core';
19
+
20
+ class AddImages extends React.Component
21
+ {
22
+ static defaultProps = {
23
+ parentStyle: null, //style passed to MultiImagePicker
24
+ prospectInst: null, //optional prospect class instance for desired prospect (project/appt) that is passed back to props.addPicture
25
+ addPicture: null, //optional function that adds one picture to the prospect (uses default if none specified)
26
+ //maxCount: null, //max number of images that can be selected. Passed to MultiImagePicker. If not commented out, causes crash, so leave it this way.
27
+ callback: null, //function to call after images added
28
+ hitSlop: null, //hitSlop passed to MultiImagePicker
29
+ allowEdit: true, //whether or not to allow user to edit file names and add commehts
30
+ annotationAllowed: false
31
+ };
32
+
33
+ constructor (props)
34
+ {
35
+ super(props);
36
+ this.state = {
37
+ showAttaching: false,
38
+ showAdd: false,
39
+ allImageDataValid: true,
40
+ showDescription: false,
41
+ saveToDevice: true //default to true in case props.allowEdit is false, so it saves to camera roll even if the checkbox not displayed to give them the option to disable saving to camera roll
42
+ };
43
+
44
+ this._mounted = false;
45
+ this.onImageSelect = this.onImageSelect.bind(this);
46
+ this.setAllImageDataValid = this.setAllImageDataValid.bind(this);
47
+ this.onAttach = this.onAttach.bind(this);
48
+ this.triggerAction = this.triggerAction.bind(this);
49
+ this.imgArr = []; //temp array for holding selected images to attach, before title & desc updated
50
+ this.imgDescArr = []; //temp array for holding descriptions of selected images, before saved to project
51
+ this.imgValidArr = []; //temp array for holding boolean value specifying whether each image title is valid or not
52
+ this.imgSource = null; //temp value designating picker type used, if image was "taken" from device now, or image(s) chosen from "library"
53
+ }
54
+
55
+ componentDidMount() {
56
+ this._mounted = true;
57
+ }
58
+ componentWillUnmount() {
59
+ this._mounted = false;
60
+ }
61
+
62
+ triggerAction() {
63
+ this.Picker.showActionSheet();
64
+ }
65
+
66
+ async hasAndroidWritePermission() {
67
+ try {
68
+ const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
69
+
70
+ const hasPermission = await PermissionsAndroid.check(permission);
71
+ if (hasPermission) {
72
+ console.log("Has permission: " + permission);
73
+ return true;
74
+ }
75
+
76
+ console.log("Permission request: " + permission);
77
+ const status = await PermissionsAndroid.request(permission);
78
+ console.log("Permission request status: " + status);
79
+ return status === 'granted';
80
+ } catch (err) {
81
+ console.log(err);
82
+ }
83
+ }
84
+
85
+ async addPicturesToProject() {
86
+ //go through all images selected and add to project
87
+
88
+ try {
89
+
90
+ loaderHandler.showLoader("Saving Pictures...");
91
+ let cRef = this;
92
+
93
+ //save image to device library if it was just taken, if they selected to save to device, or didn't have the option to select that (allowEdit=false)
94
+ // NOTE: only saving photos to camera roll for iOS currently since the cameraroll lib doesn't
95
+ // support it for android (with targetSDKVersion=30) yet, as of v4.1.2
96
+ if (Platform.OS !== "android") { //TODO: WILL REMOVE this line once it's working for android
97
+ if (cRef.imgSource === "taken" && cRef.state.saveToDevice) {
98
+ if (Platform.OS === "android" && !(await cRef.hasAndroidWritePermission())) {
99
+ console.log("Skip saving picture to android camera roll");
100
+ } else {
101
+ CameraRoll.save(cRef.imgArr[0].path)
102
+ .then(url => {
103
+ console.log("CameraRoll.save success")
104
+ })
105
+ .catch(err => {
106
+ console.log("CameraRoll.save failed, Error: " + err)
107
+ });
108
+ }
109
+ }
110
+ }
111
+
112
+ //console.log("----addPicturesToProject: Before For Loop; imgArr.length=" + cRef.imgArr.length);
113
+ for (let i = 0; i < cRef.imgArr.length; i++) {
114
+ //console.log("----addPicturesToProject: In For Loop; Before addOnePictureToProject(); i=" + i);
115
+ if (cRef.props.addPicture) { //if they supplied a function to call
116
+ await cRef.props.addPicture(cRef.imgArr[i], cRef.imgDescArr[i], cRef.props.prospectInst);
117
+ } else { //otherwise use the default one in API
118
+ await Api.getApi().addOnePictureToProject(cRef.imgArr[i], cRef.imgDescArr[i], cRef.props.prospectInst);
119
+ }
120
+ //console.log("----addPicturesToProject: In For Loop; After addOnePictureToProject(); i=" + i);
121
+ }
122
+
123
+ //console.log("----addPicturesToProject: returning true");
124
+ loaderHandler.hideLoader();
125
+ return true;
126
+
127
+ } catch(err2) {
128
+
129
+ console.log("----addPicturesToProject: returning false; ERROR: " + err2.toString());
130
+ loaderHandler.hideLoader();
131
+ return false;
132
+ }
133
+ }
134
+
135
+ async onImageSelect(payload) {
136
+ //handle return of selected images from MultiImagePicker
137
+ //payload expected (json): {index: integer, imageArray: [image info], imageDescArray: [image descriptions], imageValidArray: [array of true booleans], imageSource: ["taken" or "library"]}
138
+
139
+ let cRef = this;
140
+
141
+ cRef.imgArr = payload.imageArray;
142
+ cRef.imgDescArr = payload.imageDescArray;
143
+ cRef.imgValidArr = payload.imageValidArray;
144
+ cRef.imgSource = payload.imageSource;
145
+ if (cRef.props.allowEdit) {
146
+ let std = await Api.getApi().getDefaultSavePhotosToDevice();
147
+ if(cRef._mounted) cRef.setState({showAdd: true, saveToDevice: std});
148
+ } else {
149
+ //skip editing, just process attachments
150
+ cRef.onAttach();
151
+ }
152
+ }
153
+
154
+ setAllImageDataValid(allValid) {
155
+ //handle return of selected images from MultiImagePicker <SelectedImages>
156
+ //payload expected: (boolean) true if all selected images are valid, false otherwise
157
+ let cRef = this;
158
+ let initAllValid = cRef.state.allImageDataValid;
159
+ if (allValid !== initAllValid) {
160
+ //need to set state since overall validity flipped
161
+ if(cRef._mounted) cRef.setState({allImageDataValid: allValid});
162
+ }
163
+ }
164
+
165
+ onPressCheckbox() {
166
+ this.setState({saveToDevice: !this.state.saveToDevice});
167
+ }
168
+
169
+ onClose() {
170
+ //clicked Close icon to close attach selected pictures modal
171
+ let cRef = this;
172
+ if(cRef._mounted) cRef.setState({showAttaching: false, showAdd: false});
173
+ }
174
+ onAttach() {
175
+ //clicked Attach button to attach selected pictures
176
+ let cRef = this;
177
+ if (cRef._mounted) {
178
+ cRef.setState({showAttaching: false, showAdd: false}, async function () {
179
+ await cRef.addPicturesToProject();
180
+ if (cRef.props.allowEdit && (cRef.imgSource === "taken")) {
181
+ //only save user selection if they had a chance to enable/disable sabving to camera roll
182
+ await Api.getApi().setDefaultSavePhotosToDevice(cRef.state.saveToDevice);
183
+ }
184
+ if (cRef.props.callback) {
185
+ cRef.props.callback();
186
+ }
187
+ });
188
+ }
189
+ }
190
+
191
+ render ()
192
+ {
193
+ let cRef = this;
194
+ if (cRef.state.showAttaching) {
195
+ return (
196
+ <LoadingOverlay/>
197
+ );
198
+ }
199
+ if (cRef.state.showAdd) {
200
+ //If clicked Add button and selected images, show modal of selected images so user can edit title/descriptions before saving to project
201
+
202
+ return (
203
+ <Modal presentationStyle={"fullScreen"} animationType={"slide"}>
204
+ <SafeAreaView style={styles.Page}>
205
+ <View style={styles.NavProjectMain}>
206
+ <TouchableOpacity hitSlop={{top: 20, bottom: 20, left: 20, right: 20}}
207
+ onPress={() => {cRef.onClose()}}>
208
+ <View style={styles.NavProjectButton}>
209
+ <Icons.IconClose width="16" height="16" viewBox="0 0 16 16" />
210
+ </View>
211
+ </TouchableOpacity>
212
+ <View style={styles.NavProjectTextContainer}>
213
+ <View style={styles.NavProjectTextWrap}>
214
+ <Text style={styles.NavProjectText}>Photos to Add</Text>
215
+ </View>
216
+ </View>
217
+ <TouchableOpacity hitSlop={{top: 20, bottom: 20, left: 20, right: 20}}
218
+ onPress={() => {cRef.onAttach()}} disabled={!this.state.allImageDataValid}>
219
+ <Text style={this.state.allImageDataValid ? styles.ButtonTextRightActive : styles.ButtonTextRightDisabled}>Attach</Text>
220
+ </TouchableOpacity>
221
+ </View>
222
+ {(Platform.OS !== "android") && (cRef.imgSource === "taken") && <TouchableOpacity style={styles.SaveToDeviceWrapper}
223
+ onPress={() => cRef.onPressCheckbox()}>
224
+ <View style={styles.SaveToDeviceCheckBox}>
225
+ <CheckBox containerStyle={styles.CheckboxContainer}
226
+ checkboxStyle={styles.CheckBox}
227
+ checked={cRef.state.saveToDevice}
228
+ onChange={(checked) => cRef.onPressCheckbox()}/>
229
+ </View>
230
+ <Text style={stdStyles.S2}>Save Photo to Device</Text>
231
+ </TouchableOpacity>}
232
+ {/*<KeyboardAwareScrollView contentContainerStyle={styles.ScrollViewContainer} keyboardShouldPersistTaps='always'>*/}
233
+ <KeyboardAvoidingView behavior="padding" enabled>
234
+ <ScrollView contentContainerStyle={styles.ScrollViewContainer} keyboardShouldPersistTaps='handled'>
235
+
236
+ <SelectedImages imgArr={cRef.imgArr} imgDescArr={cRef.imgDescArr} imgValidArr={cRef.imgValidArr} callback={cRef.setAllImageDataValid} annotationAllowed={cRef.props.annotationAllowed}/>
237
+
238
+ </ScrollView>
239
+ </KeyboardAvoidingView>
240
+ {/*</KeyboardAwareScrollView>*/}
241
+ </SafeAreaView>
242
+ </Modal>
243
+ );
244
+ } else {
245
+ return (
246
+ <MultiImagePicker ref={o => cRef.Picker = o} hitSlop={cRef.props.hitSlop} maxCount={cRef.props.maxCount} parentStyle={cRef.props.parentStyle} callback={cRef.onImageSelect}>
247
+ {cRef.props.children}
248
+ </MultiImagePicker>
249
+ )
250
+ }
251
+ }
252
+ }
253
+
254
+ let styles = StyleSheet.create({
255
+ Page: {
256
+ backgroundColor: colors.white,
257
+ flex: 1,
258
+ },
259
+ ScrollViewContainer: {
260
+ paddingBottom: 100,
261
+ },
262
+ NavProjectMain: {
263
+ flexDirection: 'row',
264
+ //flex: 1,
265
+ minHeight: 66,
266
+ alignItems: 'center',
267
+ paddingLeft: 16,
268
+ //borderColor: 'black', borderWidth: 1
269
+ },
270
+ NavProjectButton: {
271
+ paddingRight: 25
272
+ },
273
+ NavProjectTextContainer: {
274
+ flex: 1,
275
+ alignItems: 'flex-start',
276
+ justifyContent: 'center'
277
+ },
278
+ NavProjectTextWrap: {
279
+ flexDirection: 'row',
280
+ alignItems: 'center',
281
+ //paddingTop: 2
282
+ },
283
+ NavProjectText: {
284
+ fontFamily: AppStyler.helper('fontFamily')("bold"),
285
+ fontSize: 20,
286
+ paddingRight: 10
287
+ },
288
+ NavProjectTextSub: {
289
+ fontSize: 12,
290
+ color: colors.black60
291
+ },
292
+ ButtonTextRightActive: {
293
+ fontFamily: AppStyler.helper('fontFamily')('medium'),
294
+ fontSize: 18,
295
+ paddingRight: 25,
296
+ textAlign: 'right',
297
+ color: colors.blue,
298
+ opacity: 1
299
+ },
300
+ ButtonTextRightDisabled: {
301
+ fontFamily: AppStyler.helper('fontFamily')('medium'),
302
+ fontSize: 18,
303
+ paddingRight: 25,
304
+ textAlign: 'right',
305
+ color: colors.blue,
306
+ opacity: 0.38
307
+ },
308
+ SaveToDeviceWrapper: {
309
+ //backgroundColor: colors.white,
310
+ borderTopWidth: 1,
311
+ borderBottomWidth: 1,
312
+ borderColor: colors.black05,
313
+ paddingVertical: 5,
314
+ flexDirection: "row",
315
+ alignItems: "center",
316
+ justifyContent: 'flex-start',
317
+ },
318
+ CheckboxContainer: {
319
+ },
320
+ SaveToDeviceCheckBox: {
321
+ flex: 0,
322
+ flexDirection: "row",
323
+ justifyContent: "center",
324
+ alignItems: "center",
325
+ paddingTop: 5,
326
+ marginHorizontal: 20,
327
+ },
328
+ CheckBox: {
329
+ width: 18,
330
+ height: 18,
331
+ },
332
+ });
333
+
334
+ export default AddImages;
@@ -0,0 +1,161 @@
1
+ import * as React from 'react';
2
+ import {View, TouchableOpacity} from 'react-native';
3
+ import ActionSheet from '@alessiocancian/react-native-actionsheet';
4
+ import ImagePicker from 'react-native-image-crop-picker';
5
+ import ImageResizer from '@bam.tech/react-native-image-resizer';
6
+ import {Api} from '@supportworks/api-core';
7
+
8
+ class MultiImagePicker extends React.Component {
9
+
10
+ static defaultProps = {
11
+ useCamera: 'Take Photo...',
12
+ useLibrary: 'Choose from Library...',
13
+ title: 'Add Photo(s)',
14
+ parentStyle: null, //style to be applied to the parent (view) in the render function. Otherwise, a 'style' prop is applied to the TouchableOpacity, which is a child of View.
15
+ customButtons: [], //array of titles of custom buttons to display, pre-pended to action sheet buttons (optional)
16
+ maxCount: 25, //max number of images that can be selected
17
+ callbackData: null, //data appended to payload and passed with callback function (optional)
18
+ callback: null //callback function (optional)
19
+ };
20
+
21
+ constructor(props) {
22
+ super(props);
23
+ this.imgArr = []; //temp array for holding selected images to attach, before title & desc updated
24
+ this.imgDescArr = []; //temp array for holding descriptions of selected images, before saved to project
25
+ this.imgValidArr = []; //temp array for holding boolean value specifying whether each image title is valid or not
26
+ this.pickerDone = this.pickerDone.bind(this);
27
+ this.showActionSheet = this.showActionSheet.bind(this);
28
+ this.takeOnePicture = this.takeOnePicture.bind(this);
29
+ }
30
+
31
+ async pickerDone(index, cancelIndex, imageSource = null) {
32
+ //user is done using the picker to select images. index: index of button that was clicked.
33
+ // cancelIndex: index of the cancel button, so we know which button was clicked, since we know cancel is the last index available.
34
+ // imageSource: "taken" if image was taken from device now, "library" if image(s) were selected from library
35
+ let cRef = this;
36
+
37
+ if (cRef.props.callback) {
38
+ for(let i=0;i<cRef.imgArr.length;i++){
39
+ let x = await ImageResizer.createResizedImage(cRef.imgArr[i].path, 2000, 2000, "JPEG", 80, 0);
40
+ await Api.getApi().moveLocalFile(x.path, cRef.imgArr[i].path, true);
41
+ }
42
+ cRef.props.callback({index: index, cancelIndex: cancelIndex, imageArray: cRef.imgArr, imageDescArray: cRef.imgDescArr, imageValidArray: cRef.imgValidArr, imageSource: imageSource, callbackData: cRef.props.callbackData});
43
+ }
44
+ }
45
+
46
+ async takeOnePicture(index, cancelIndex, options, depth, callback) {
47
+ let cRef = this;
48
+ if(depth>cRef.props.maxCount) {
49
+ callback();
50
+ return;
51
+ }
52
+ ImagePicker.openCamera(options).then(async image => {
53
+ console.log("SWSI take photo, image: " + JSON.stringify(image));
54
+ cRef.imgArr.push(image);
55
+ cRef.imgDescArr.push('');
56
+ cRef.imgValidArr.push(true);
57
+ await cRef.takeOnePicture(index, cancelIndex, options, depth + 1, callback);
58
+ }).catch((e)=>{
59
+ callback();
60
+ });
61
+ }
62
+
63
+ usePicker(index, cancelIndex) {
64
+ //index: index of ActionSheet. Depends on whether custom buttons added. Last 3 are fixed (Take Photo, Choose from Library, Cancel). Anything before that is custom button.
65
+ // Custom buttons can be sent using customButtons prop.
66
+ //results - sets cRef.imgArr to an array of image info that the picker library provided
67
+ // sets cRef.imgDescArray to an array of the image descriptions
68
+ // initializes cRef.imgValidArr to an array of booleans (all true) for all selected images, to be used/updated by calling code as needed
69
+
70
+ let cRef = this;
71
+ let options = {
72
+ multiple: true,
73
+ maxFiles: cRef.props.maxCount, //ios only
74
+ cropping: false,
75
+ mediaType: 'photo'
76
+ };
77
+ cRef.imgArr = []; //clear selected images
78
+ cRef.imgDescArr = []; //clear descriptions for selected images
79
+ cRef.imgValidArr = []; //clear valid flags for selected images
80
+ let takePhotoIndex = cancelIndex - 2;
81
+ let chooseLibIndex = cancelIndex - 1;
82
+ let imageSource = null;
83
+
84
+ switch (index) {
85
+ case takePhotoIndex:
86
+ //Take Photo
87
+ cRef.takeOnePicture(index, cancelIndex, options, 1, ()=>{
88
+ if(cRef.imgArr.length>0){
89
+ imageSource = "taken";
90
+ cRef.pickerDone(index, cancelIndex, imageSource);
91
+ }
92
+ });
93
+ break;
94
+
95
+ case chooseLibIndex:
96
+ //Choose from Library
97
+ ImagePicker.openPicker(options).then(async images => {
98
+ console.log("SWSI choose photo, images: " + JSON.stringify(images));
99
+ if (images.length > cRef.props.maxCount) {
100
+ alert("You may only select a max of " + cRef.props.maxCount + " photo(s)");
101
+ } else {
102
+ cRef.imgArr = images;
103
+ //create array of blank entries for descriptions they might add. Also, an array for validitity of titles
104
+ for (let i = 0; i < cRef.imgArr.length; i++) {
105
+ cRef.imgDescArr.push('');
106
+ cRef.imgValidArr.push(true);
107
+ }
108
+ imageSource = "library";
109
+ cRef.pickerDone(index, cancelIndex, imageSource);
110
+ }
111
+ }).catch(err1 => console.log("----usePicker, openPicker: User Cancelled Image Picker (choose from lib), error: "+err1.message));
112
+ break;
113
+
114
+ case cancelIndex:
115
+ //user pressed cancel (last button) or a custom button
116
+ console.log("----usePicker(): User pressed cancel");
117
+ break;
118
+
119
+ default:
120
+ //user pressed cancel (last button) or a custom button
121
+ console.log("----usePicker(): User pressed custom button");
122
+ cRef.pickerDone(index, cancelIndex);
123
+ return;
124
+ } // end switch
125
+
126
+ }
127
+
128
+ showActionSheet = () => {
129
+ //open ActionSheet
130
+ this.ActionSheet.show();
131
+ };
132
+
133
+ render() {
134
+ let cRef = this;
135
+ let customButtonArr = cRef.props.customButtons;
136
+ let fixedButtonArr = [cRef.props.useCamera, cRef.props.useLibrary, 'Cancel'];
137
+ let buttonArr = customButtonArr.concat(fixedButtonArr);
138
+ let cancelIndex = buttonArr.length-1;
139
+
140
+ return (
141
+ <View style={cRef.props.parentStyle}>
142
+ <ActionSheet
143
+ ref={o => cRef.ActionSheet = o}
144
+ title={cRef.props.title}
145
+ options={buttonArr}
146
+ cancelButtonIndex={cancelIndex}
147
+ onPress={(index) => {
148
+ cRef.usePicker(index, cancelIndex)
149
+ }}>
150
+ </ActionSheet>
151
+
152
+ <TouchableOpacity {...cRef.props} onPress={() => {cRef.props.children ? cRef.showActionSheet() : null}}>
153
+ {cRef.props.children}
154
+ </TouchableOpacity>
155
+
156
+ </View>
157
+ );
158
+ }
159
+ }
160
+
161
+ export default MultiImagePicker;
@@ -0,0 +1,79 @@
1
+ import * as React from 'react';
2
+ import {
3
+ View
4
+ } from 'react-native';
5
+ import SingleImage from "./SingleImage";
6
+
7
+ class SelectedImages extends React.Component {
8
+
9
+ static defaultProps = {
10
+ imgArr: [], //array of image info (required)
11
+ imgDescArr: [], //array of image descriptions (optional)
12
+ imgValidArr: [], //array of booleans (required)
13
+ callback: null, //function (option) callback function
14
+ annotationAllowed: false
15
+ };
16
+
17
+ constructor(props) {
18
+ super(props);
19
+ this.onChangeImageInfo = this.onChangeImageInfo.bind(this);
20
+ }
21
+
22
+ onChangeImageInfo(payload) {
23
+ //callback from ProjectAttachmentsSelectedImage, to update imgArr with any changes (called per keystroke)
24
+ //payload expected (json): {name: 'fieldname', value: 'fieldvalue', isValid: boolean, imgIndex: number});
25
+ let cRef = this;
26
+ //console.log("-----onChangeImageInfo: start");
27
+ //console.log("-----name: " + payload.name);
28
+ //console.log("-----value: " + payload.value);
29
+ //console.log("-----isValid: " + payload.isValid);
30
+ //console.log("-----imgIndex: " + payload.imgIndex);
31
+
32
+ switch (payload.name) {
33
+ case "title":
34
+ cRef.props.imgArr[payload.imgIndex].filename = payload.value;
35
+ cRef.props.imgValidArr[payload.imgIndex] = payload.isValid;
36
+
37
+ //Loop through all imgArr objects and set this.allImageDataValid accordingly
38
+ //let initAllValid = cRef.state.allImageDataValid;
39
+ let allValid = true;
40
+ for (let i = 0; i < cRef.props.imgValidArr.length; i++) {
41
+ //if any are invalid, set allValid to false
42
+ if (!cRef.props.imgValidArr[i]) {
43
+ allValid = false;
44
+ break; //no need to check others
45
+ }
46
+ }
47
+
48
+ if (cRef.props.callback) {
49
+ cRef.props.callback(allValid);
50
+ }
51
+
52
+ break;
53
+ case "desc":
54
+ cRef.props.imgDescArr[payload.imgIndex] = payload.value;
55
+ break;
56
+ }
57
+ }
58
+
59
+ render() {
60
+ let cRef = this;
61
+
62
+ //put selected images into array
63
+ console.log("SWSI cRef.imgArr: " + JSON.stringify(cRef.props.imgArr));
64
+ let selImages = cRef.props.imgArr.map(function (o, idx) {
65
+ //let fname = o.filename;
66
+ //let path = o.path;
67
+ return (
68
+ <View key={idx}>
69
+ <SingleImage imgObject={o} imgIndex={idx} callback={cRef.onChangeImageInfo} annotationAllowed={cRef.props.annotationAllowed}/>
70
+ </View>
71
+ );
72
+ });
73
+
74
+ return selImages;
75
+
76
+ }
77
+ }
78
+
79
+ export default SelectedImages;
@@ -0,0 +1,164 @@
1
+ import * as React from 'react';
2
+ import {
3
+ Text,
4
+ View,
5
+ Modal,
6
+ SafeAreaView,
7
+ TouchableOpacity,
8
+ StyleSheet, ScrollView, KeyboardAvoidingView, Platform, PermissionsAndroid,
9
+ Image, Dimensions
10
+ } from 'react-native';
11
+ import Moment from 'moment';
12
+ import {TextInputSWMD} from '@supportworks/SWMaterialDesign';
13
+ import { Block, Grid, Section } from 'react-native-responsive-layout';
14
+ import {Api} from '@supportworks/api-core';
15
+ import AppStyler, {colors, stdStyles} from "@supportworks/app-styler";
16
+ import { Canvas } from '@supportworks/react-native-annotate';
17
+ import ImageResizer from '@bam.tech/react-native-image-resizer';
18
+
19
+ class SingleImage extends React.Component {
20
+
21
+ static defaultProps = {
22
+ imgObject: {}, //object. {
23
+ imgIndex: 0, //integer
24
+ callback: null, //callback function
25
+ annotationAllowed: false
26
+ };
27
+
28
+ constructor (props)
29
+ {
30
+ super(props);
31
+ this.onChangeTitle = this.onChangeTitle.bind(this);
32
+ this.onChangeDesc = this.onChangeDesc.bind(this);
33
+ this.onReadyCanvas = this.onReadyCanvas.bind(this);
34
+ this.onCloseCanvas = this.onCloseCanvas.bind(this);
35
+ this.onSaveCanvas = this.onSaveCanvas.bind(this);
36
+ this.initialLoad = true;
37
+ this.txtTitle = !!props.imgObject.defaultName ? props.imgObject.defaultName : Moment(new Date()).format('YYYY-MM-DD_hmmssa');
38
+ this.txtTitleEditable = !!props.imgObject.defaultName ? (props.imgObject.defaultOnly===false) : true;
39
+ this.txtDesc = '';
40
+ this.state = {
41
+ showCanvas: false,
42
+ version: 1
43
+ }
44
+ }
45
+
46
+ onChangeTitle(payload) {
47
+ //concatenate the title and file extension to make the filename
48
+ //payload expected (json): {inputValue: 'new field value', isValueValid: boolean}
49
+ //console.log("-----onChangeTitle: start");
50
+ let cRef = this;
51
+ let imgObj = cRef.props.imgObject;
52
+ //console.log("SWSI imgObj: " + JSON.stringify(imgObj));
53
+ let fname = imgObj.path; //using path rather than filename since a photo they just took has a null filename value
54
+ let ext = "." + fname.split(".").pop(); //file extension, used in callback
55
+ //cRef.txtTitle = payload.inputValue + ext;
56
+ cRef.txtTitle = payload.inputValue;
57
+ let isTitleValid = payload.isValueValid;
58
+ if (cRef.props.callback) {
59
+ cRef.props.callback({name: 'title', value: cRef.txtTitle + ext, isValid: isTitleValid, imgIndex: cRef.props.imgIndex});
60
+ }
61
+ //console.log("-----onChangeTitle end: title=" + cRef.txtTitle + "; isTitleValid=" + isTitleValid);
62
+ }
63
+ onChangeDesc(payload) {
64
+ let cRef = this;
65
+ cRef.txtDesc = payload.inputValue;
66
+ if (cRef.props.callback) {
67
+ cRef.props.callback({name: 'desc', value: cRef.txtDesc, isValid: true, imgIndex: cRef.props.imgIndex});
68
+ }
69
+ //console.log("-----onChangeDesc end: description=" + cRef.txtDesc);
70
+ }
71
+ async onReadyCanvas(path){
72
+ let data = await Api.getApi().getBase64FromLocal(path);
73
+ let json = await Api.getApi().getUTF8FromLocal(path+".json");
74
+ let origData = await Api.getApi().getBase64FromLocal(path+".orig");
75
+ let defaultSettings = await Api.getApi().getCanvasSettings();
76
+ if(json=="" || origData==""){
77
+ this.setState({showCanvas: true, canvasData: data, annotationJson: {history: [], settings: defaultSettings}, filePath: path});
78
+ }else{
79
+ this.setState({showCanvas: true, canvasData: origData, annotationJson: JSON.parse(json), filePath: path});
80
+ }
81
+ }
82
+ async onSaveCanvas(info){
83
+ await Api.getApi().writeFile(this.state.filePath+".orig", this.state.canvasData, 'base64');
84
+ let printFile = await ImageResizer.createResizedImage(info.fileName, 500, 500, "JPEG", 80, 0);
85
+ let savePrintFile = this.state.filePath.replace(/(\.[\w\d_-]+)$/i, '_print$1');
86
+ await Api.getApi().moveLocalFile(printFile.uri, savePrintFile, true);
87
+ await Api.getApi().moveLocalFile(info.fileName, this.state.filePath, true);
88
+ await Api.getApi().writeFile(this.state.filePath+".json", JSON.stringify({history: info.history, settings: info.settings}), 'utf8');
89
+ await Api.getApi().setCanvasSettings(info.settings);
90
+ this.setState({version: this.state.version+1, showCanvas: false, canvasData: "", filePath: ""});
91
+ }
92
+ onCloseCanvas(){
93
+ this.setState({showCanvas: false, canvasData: "", filePath: ""});
94
+ }
95
+ render () {
96
+ let cRef = this;
97
+ let imgObj = cRef.props.imgObject;
98
+ let path = imgObj.path;
99
+ let screenWidth = Dimensions.get('window').width;
100
+ let imageWidth = (screenWidth < 411) ? (screenWidth * 0.50) : (screenWidth * .20); //less than 411 is xsmall, >= 411 is small and above
101
+ let imageHeight = imageWidth;
102
+ if (cRef.initialLoad) { //set title value first time loading modal in case they never change it before saving
103
+ cRef.initialLoad = false;
104
+ cRef.onChangeTitle({inputValue: cRef.txtTitle, isValueValid: true});
105
+ }
106
+ if(cRef.state.showCanvas){
107
+ return (
108
+ <Modal presentationStyle={"fullScreen"} animationType={"slide"}>
109
+ <SafeAreaView style={styles.Page}>
110
+ <Canvas settings={cRef.state.annotationJson.settings} history={cRef.state.annotationJson.history} base64image={'data:image/jpeg;base64,'+cRef.state.canvasData} onSave={cRef.onSaveCanvas} onClose={cRef.onCloseCanvas} />
111
+ </SafeAreaView>
112
+ </Modal>
113
+ );
114
+ }else{
115
+ return (
116
+ <Grid>
117
+ <Section style={{paddingTop: 20, marginLeft: 20, marginRight: 20, borderBottomColor: 'lightgrey', borderBottomWidth: 1}}>
118
+ <Block xsSize="100%" smSize="25%">
119
+ {cRef.props.annotationAllowed ?
120
+ <TouchableOpacity onPress={()=>{ cRef.onReadyCanvas(path) }}>
121
+ <Image
122
+ resizeMode={'cover'}
123
+ style={{width: imageWidth, height: imageHeight, marginBottom: 20}}
124
+ source={{uri:Api.getApi().fullImagePath(path)+"?x="+cRef.state.version}}
125
+ />
126
+ </TouchableOpacity>
127
+ :
128
+ <Image
129
+ resizeMode={'cover'}
130
+ style={{width: imageWidth, height: imageHeight, marginBottom: 20}}
131
+ source={{uri:"file://"+path+"?x="+cRef.state.version}}
132
+ />
133
+ }
134
+ </Block>
135
+ <Block xsSize="100%" smSize="75%">
136
+ <TextInputSWMD
137
+ label={'Title*'} value={cRef.txtTitle} multiline={false} maxLength={255}
138
+ validationType={'1'} clearButtonMode={'always'} required={true}
139
+ validationFailMsg={'Title contains invalid characters'}
140
+ callback={cRef.onChangeTitle}
141
+ editable={cRef.txtTitleEditable}
142
+ disabled={!cRef.txtTitleEditable}
143
+ />
144
+ <TextInputSWMD
145
+ label={'Description'} value={cRef.txtDesc} multiline={true} maxLength={500}
146
+ validationType={'0'}
147
+ callback={cRef.onChangeDesc}
148
+ />
149
+ </Block>
150
+ </Section>
151
+ </Grid>
152
+ );
153
+ }
154
+ }
155
+ }
156
+
157
+ let styles = StyleSheet.create({
158
+ Page: {
159
+ backgroundColor: colors.black,
160
+ flex: 1,
161
+ }
162
+ });
163
+
164
+ export default SingleImage;
@@ -0,0 +1,12 @@
1
+ import { DeviceEventEmitter } from 'react-native';
2
+
3
+ const loaderHandler = {
4
+ hideLoader () {
5
+ DeviceEventEmitter.emit('changeLoadingEffect', {isVisible: false});
6
+ },
7
+ showLoader (title) {
8
+ DeviceEventEmitter.emit('changeLoadingEffect', {title, isVisible: true});
9
+ }
10
+ };
11
+
12
+ module.exports = loaderHandler;
@@ -0,0 +1,47 @@
1
+ import AsyncStorage from "@react-native-async-storage/async-storage";
2
+
3
+ export default class MIPickerApi
4
+ {
5
+ /**
6
+ *
7
+ * Initialize property getters and setters
8
+ * */
9
+
10
+ setDefaultSavePhotosToDevice(defaultSavePhotosToDevice) {
11
+ //AsyncStorage must be a string value, so converting boolean to string to save to AS
12
+ let newValBool = defaultSavePhotosToDevice;
13
+ let newValStr;
14
+ if ((newValBool === null) || (newValBool === true)) {
15
+ newValBool = true; //default
16
+ newValStr = "Y";
17
+ } else {
18
+ newValBool = false;
19
+ newValStr = "N";
20
+ }
21
+ AsyncStorage.setItem('@SavePhotosToDevice', newValStr)
22
+ .then(res => {
23
+ console.log("Set defaultSavePhotosToDevice: AsyncStorage.setItem success, set to value: " + newValStr);
24
+ this._defaultSavePhotosToDevice = newValBool;
25
+ })
26
+ .catch(err => {
27
+ console.log("Set defaultSavePhotosToDevice: AsyncStorage.setItem failed, Error: " + err);
28
+ this._defaultSavePhotosToDevice = newValBool;
29
+ });
30
+ }
31
+ async getDefaultSavePhotosToDevice() {
32
+ console.log("in Get defaultSavePhotosToDevice");
33
+ if ((this._defaultSavePhotosToDevice !== null) && (this._defaultSavePhotosToDevice !== undefined)) {
34
+ return this._defaultSavePhotosToDevice;
35
+ }
36
+ console.log("in Get defaultSavePhotosToDevice, trying to get value from AsyncStorage");
37
+ //not a value yet, so look in AsyncStorage
38
+ let retVal = await AsyncStorage.getItem("@SavePhotosToDevice");
39
+ if (retVal === "N") {
40
+ console.log("Get defaultSavePhotosToDevice: return false");
41
+ return false;
42
+ } else {
43
+ console.log("Get defaultSavePhotosToDevice: return true");
44
+ return true;
45
+ }
46
+ }
47
+ }