Skip to content

Commit ef071ce

Browse files
committed
assignment 4
1 parent 1c75556 commit ef071ce

File tree

4 files changed

+227
-105
lines changed

4 files changed

+227
-105
lines changed

Multiplatform Mobile App Development with React Native/confusion/components/LoginComponent.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class LoginTab extends Component {
9090
/>
9191
}
9292
buttonStyle={{ backgroundColor: '#512da8' }}
93-
containerStyle={{ margin: 40 }}
93+
containerStyle={{ margin: 5 }}
9494
/>
9595

9696
<Button
@@ -106,7 +106,7 @@ class LoginTab extends Component {
106106
/>
107107
}
108108
titleStyle={{ color: 'blue', fontSize: 20 }}
109-
containerStyle={{ margin: 40 }}
109+
containerStyle={{ margin: 5 }}
110110
/>
111111

112112
</View>
@@ -154,19 +154,33 @@ class RegisterTab extends Component {
154154
}
155155

156156
processImage = async (imageUri) => {
157-
let processedImage = await ImageManipulator.manipulate(
157+
let processedImage = await ImageManipulator.manipulateAsync(
158158
imageUri,
159159
[
160160
{resize: {width: 400}}
161161
],
162162
{format: 'png'}
163163
);
164164
console.log(processedImage);
165-
this.setState({ imageUrl : processedImage.uri });
165+
this.setState({imageUrl: processedImage.uri });
166166

167167
}
168168

169-
169+
getImageFromGallery = async ()=>{
170+
const cameraPermission = await Permissions.askAsync(Permissions.CAMERA);
171+
const cameraRollPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL);
172+
173+
if (cameraPermission.status === 'granted' && cameraRollPermission.status === 'granted') {
174+
let capturedImage = await ImagePicker.launchImageLibraryAsync({
175+
allowsEditing: true,
176+
aspect: [4, 3],
177+
});
178+
if (!capturedImage.cancelled) {
179+
console.log(capturedImage);
180+
this.processImage(capturedImage.uri);
181+
}
182+
}
183+
}
170184

171185
handleRegister = () => {
172186
console.log(JSON.stringify(this.state))
@@ -189,7 +203,12 @@ class RegisterTab extends Component {
189203
title='Camera'
190204
onPress={this.getImageFromCamera}
191205
containerStyle={{ paddingTop: 10 }}
192-
/>
206+
/>
207+
<Button
208+
title='Gallery'
209+
onPress={this.getImageFromGallery}
210+
containerStyle={{ paddingTop: 10 }}
211+
/>
193212
</View>
194213

195214
<Input
@@ -251,7 +270,7 @@ class RegisterTab extends Component {
251270
/>
252271
}
253272
buttonStyle={{ backgroundColor: '#512da8' }}
254-
containerStyle={{ margin: 40 }}
273+
containerStyle={{ margin: 5 }}
255274
/>
256275

257276
</View>
@@ -309,23 +328,23 @@ function Login() {
309328
const styles = StyleSheet.create({
310329
container: {
311330
justifyContent: 'center',
312-
margin: 20
331+
margin: 5
313332
},
314333
imageContainer: {
315334
flex: 1,
316335
flexDirection: 'row',
317-
margin: 20,
336+
margin: 5,
318337
justifyContent: 'center'
319338
},
320339
image: {
321340
width: 80,
322341
height: 60
323342
},
324343
formInput: {
325-
margin: 20
344+
margin: 5
326345
},
327346
formCheck: {
328-
margin: 20,
347+
margin: 5,
329348
backgroundColor: null
330349
}
331350
})

0 commit comments

Comments
 (0)