Adjusted camera stack and app reducer.
This commit is contained in:
@@ -6,25 +6,40 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { StyleSheet, Text, View } from "react-native";
|
import { StyleSheet, Text, View } from "react-native";
|
||||||
import { TouchableOpacity } from "react-native-gesture-handler";
|
import { TouchableOpacity } from "react-native-gesture-handler";
|
||||||
import Swipeable from "react-native-gesture-handler/Swipeable";
|
import Swipeable from "react-native-gesture-handler/Swipeable";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import { setCameraJob, setCameraJobId } from "../../redux/app/app.actions";
|
||||||
import styles from "../styles";
|
import styles from "../styles";
|
||||||
|
|
||||||
const RenderRightAction = (props) => {
|
const mapStateToProps = createStructuredSelector({
|
||||||
const navigation = useNavigation();
|
//currentUser: selectCurrentUser
|
||||||
const { t } = useTranslation();
|
});
|
||||||
return (
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
<TouchableOpacity
|
setCameraJobId: (id) => dispatch(setCameraJobId(id)),
|
||||||
style={[styles.swipe_view, styles.swipe_view_blue]}
|
setCameraJob: (job) => dispatch(setCameraJob(job)),
|
||||||
onPress={() => navigation.push("JobCamera")}
|
});
|
||||||
>
|
|
||||||
<Ionicons name="ios-camera" size={24} color="white" />
|
|
||||||
<Text style={styles.swipe_text}>{t("joblist.actions.swipecamera")}</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function JobListItem({ item }) {
|
export function JobListItem({ setCameraJob, setCameraJobId, item }) {
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
|
const RenderRightAction = (props) => {
|
||||||
|
const navigation = useNavigation();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[styles.swipe_view, styles.swipe_view_blue]}
|
||||||
|
onPress={() => {
|
||||||
|
setCameraJobId(item.id);
|
||||||
|
setCameraJob(item);
|
||||||
|
navigation.navigate("TabCamera");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Ionicons name="ios-camera" size={24} color="white" />
|
||||||
|
<Text style={styles.swipe_text}>
|
||||||
|
{t("joblist.actions.swipecamera")}
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
);
|
||||||
|
};
|
||||||
const onPress = () => {
|
const onPress = () => {
|
||||||
navigation.push("JobDetail", {
|
navigation.push("JobDetail", {
|
||||||
jobId: item.id,
|
jobId: item.id,
|
||||||
@@ -73,3 +88,4 @@ const localStyles = StyleSheet.create({
|
|||||||
marginLeft: 15,
|
marginLeft: 15,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(JobListItem);
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Text, View } from "react-native";
|
||||||
|
|
||||||
|
export default function ScreenCameraJobSearch() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text>This is the media cache screen.</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
213
components/screen-camera-roll/screen-camera-roll.component.jsx
Normal file
213
components/screen-camera-roll/screen-camera-roll.component.jsx
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
import React, { Component } from "react";
|
||||||
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
|
Button,
|
||||||
|
Clipboard,
|
||||||
|
Image,
|
||||||
|
Share,
|
||||||
|
StatusBar,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
TouchableOpacity,
|
||||||
|
View,
|
||||||
|
} from "react-native";
|
||||||
|
import { Constants } from "expo";
|
||||||
|
import * as Permissions from "expo-permissions";
|
||||||
|
import * as ImagePicker from "expo-image-picker";
|
||||||
|
export default class ScreenCameraRoll extends Component {
|
||||||
|
state = {
|
||||||
|
image: null,
|
||||||
|
uploading: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let { image } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<StatusBar barStyle="default" />
|
||||||
|
|
||||||
|
<Text style={styles.exampleText}>
|
||||||
|
Example: Upload ImagePicker result
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onPress={this._pickImage}
|
||||||
|
title="Pick an image from camera roll"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button onPress={this._takePhoto} title="Take a photo" />
|
||||||
|
|
||||||
|
{this._maybeRenderImage()}
|
||||||
|
{this._maybeRenderUploadingOverlay()}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_maybeRenderUploadingOverlay = () => {
|
||||||
|
if (this.state.uploading) {
|
||||||
|
return (
|
||||||
|
<View style={[StyleSheet.absoluteFill, styles.maybeRenderUploading]}>
|
||||||
|
<ActivityIndicator color="#fff" size="large" />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_maybeRenderImage = () => {
|
||||||
|
let { image } = this.state;
|
||||||
|
|
||||||
|
if (!image) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.maybeRenderContainer}>
|
||||||
|
<View style={styles.maybeRenderImageContainer}>
|
||||||
|
<Image source={{ uri: image }} style={styles.maybeRenderImage} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<Text
|
||||||
|
onPress={this._copyToClipboard}
|
||||||
|
onLongPress={this._share}
|
||||||
|
style={styles.maybeRenderImageText}
|
||||||
|
>
|
||||||
|
{image}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
_share = () => {
|
||||||
|
Share.share({
|
||||||
|
message: this.state.image,
|
||||||
|
title: "Check out this photo",
|
||||||
|
url: this.state.image,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_copyToClipboard = () => {
|
||||||
|
Clipboard.setString(this.state.image);
|
||||||
|
alert("Copied image URL to clipboard");
|
||||||
|
};
|
||||||
|
|
||||||
|
_takePhoto = async () => {
|
||||||
|
const { status: cameraPerm } = await Permissions.askAsync(
|
||||||
|
Permissions.CAMERA
|
||||||
|
);
|
||||||
|
|
||||||
|
const { status: cameraRollPerm } = await Permissions.askAsync(
|
||||||
|
Permissions.CAMERA_ROLL
|
||||||
|
);
|
||||||
|
|
||||||
|
// only if user allows permission to camera AND camera roll
|
||||||
|
if (cameraPerm === "granted" && cameraRollPerm === "granted") {
|
||||||
|
let pickerResult = await ImagePicker.launchCameraAsync({
|
||||||
|
allowsMultipleSelection: true,
|
||||||
|
quality: 0.8,
|
||||||
|
//allowsEditing: true,
|
||||||
|
aspect: [4, 3],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!pickerResult.cancelled) {
|
||||||
|
this.setState({ image: pickerResult.uri });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.uploadImageAsync(pickerResult.uri);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_pickImage = async () => {
|
||||||
|
const { status: cameraRollPerm } = await Permissions.askAsync(
|
||||||
|
Permissions.CAMERA_ROLL
|
||||||
|
);
|
||||||
|
|
||||||
|
// only if user allows permission to camera roll
|
||||||
|
if (cameraRollPerm === "granted") {
|
||||||
|
let pickerResult = await ImagePicker.launchImageLibraryAsync({
|
||||||
|
allowsEditing: true,
|
||||||
|
base64: true,
|
||||||
|
aspect: [4, 3],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!pickerResult.cancelled) {
|
||||||
|
this.setState({ image: pickerResult.uri });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.uploadImageAsync(pickerResult.uri);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
uploadImageAsync(pictureuri) {
|
||||||
|
let apiUrl = "http://123.123.123.123/ABC";
|
||||||
|
|
||||||
|
var data = new FormData();
|
||||||
|
data.append("file", {
|
||||||
|
uri: pictureuri,
|
||||||
|
name: "file",
|
||||||
|
type: "image/jpg",
|
||||||
|
});
|
||||||
|
|
||||||
|
fetch(apiUrl, {
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
"Content-Type": "multipart/form-data",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: data,
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log("succ ");
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log("err ");
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
alignItems: "center",
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: "center",
|
||||||
|
},
|
||||||
|
exampleText: {
|
||||||
|
fontSize: 20,
|
||||||
|
marginBottom: 20,
|
||||||
|
marginHorizontal: 15,
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
maybeRenderUploading: {
|
||||||
|
alignItems: "center",
|
||||||
|
backgroundColor: "rgba(0,0,0,0.4)",
|
||||||
|
justifyContent: "center",
|
||||||
|
},
|
||||||
|
maybeRenderContainer: {
|
||||||
|
borderRadius: 3,
|
||||||
|
elevation: 2,
|
||||||
|
marginTop: 30,
|
||||||
|
shadowColor: "rgba(0,0,0,1)",
|
||||||
|
shadowOpacity: 0.2,
|
||||||
|
shadowOffset: {
|
||||||
|
height: 4,
|
||||||
|
width: 4,
|
||||||
|
},
|
||||||
|
shadowRadius: 5,
|
||||||
|
width: 250,
|
||||||
|
},
|
||||||
|
maybeRenderImageContainer: {
|
||||||
|
borderTopLeftRadius: 3,
|
||||||
|
borderTopRightRadius: 3,
|
||||||
|
overflow: "hidden",
|
||||||
|
},
|
||||||
|
maybeRenderImage: {
|
||||||
|
height: 250,
|
||||||
|
width: 250,
|
||||||
|
},
|
||||||
|
maybeRenderImageText: {
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 10,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect, useRef } from "react";
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import { Text, View, TouchableOpacity } from "react-native";
|
import { Text, View, TouchableOpacity, SafeAreaView } from "react-native";
|
||||||
import { Camera } from "expo-camera";
|
import { Camera } from "expo-camera";
|
||||||
import {
|
import {
|
||||||
Ionicons,
|
Ionicons,
|
||||||
@@ -11,7 +11,20 @@ import * as FileSystem from "expo-file-system";
|
|||||||
import * as Permissions from "expo-permissions";
|
import * as Permissions from "expo-permissions";
|
||||||
import * as MediaLibrary from "expo-media-library";
|
import * as MediaLibrary from "expo-media-library";
|
||||||
|
|
||||||
export default function ScreenCamera() {
|
import { connect } from "react-redux";
|
||||||
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import {
|
||||||
|
selectCurrentCameraJobId,
|
||||||
|
selectCurrentCameraJob,
|
||||||
|
} from "../../redux/app/app.selectors";
|
||||||
|
|
||||||
|
const mapStateToProps = createStructuredSelector({
|
||||||
|
cameraJobId: selectCurrentCameraJobId,
|
||||||
|
cameraJob: selectCurrentCameraJob,
|
||||||
|
});
|
||||||
|
const mapDispatchToProps = (dispatch) => ({});
|
||||||
|
|
||||||
|
export function ScreenCamera({ cameraJobId, cameraJob }) {
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
const [hasPermission, setHasPermission] = useState(null);
|
const [hasPermission, setHasPermission] = useState(null);
|
||||||
const [rollPermision, setRollPermission] = useState(null);
|
const [rollPermision, setRollPermission] = useState(null);
|
||||||
@@ -86,57 +99,94 @@ export default function ScreenCamera() {
|
|||||||
return (
|
return (
|
||||||
<View style={{ display: "flex", flex: 1 }}>
|
<View style={{ display: "flex", flex: 1 }}>
|
||||||
<Camera style={{ flex: 1 }} type={type} ref={cameraRef}>
|
<Camera style={{ flex: 1 }} type={type} ref={cameraRef}>
|
||||||
<View
|
<SafeAreaView
|
||||||
style={{
|
style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: "row",
|
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
margin: 20,
|
// marginTop: 40,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={handleCameraType}
|
onPress={() => navigation.push("CameraJobSearch")}
|
||||||
style={{
|
style={{
|
||||||
alignSelf: "flex-end",
|
display: "flex",
|
||||||
|
width: "100%",
|
||||||
|
alignSelf: "flex-start",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
backgroundColor: "transparent",
|
backgroundColor: "rgba(112, 128, 144, 0.3)",
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: "bold",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MaterialCommunityIcons
|
<Text
|
||||||
name="camera-switch"
|
style={{
|
||||||
style={{ color: "#fff", fontSize: 40 }}
|
fontSize: 20,
|
||||||
/>
|
fontWeight: "bold",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{cameraJob && cameraJob.ro_number}
|
||||||
|
</Text>
|
||||||
|
<Text>
|
||||||
|
{cameraJob &&
|
||||||
|
`${cameraJob && cameraJob.ownr_fn} ${
|
||||||
|
cameraJob && cameraJob.ownr_ln
|
||||||
|
}`}
|
||||||
|
</Text>
|
||||||
|
<Text>{cameraJobId}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<TouchableOpacity
|
<View
|
||||||
onPress={handleTakePicture}
|
|
||||||
style={{
|
style={{
|
||||||
alignSelf: "flex-end",
|
flex: 1,
|
||||||
alignItems: "center",
|
flexDirection: "row",
|
||||||
backgroundColor: "transparent",
|
justifyContent: "space-between",
|
||||||
|
margin: 20,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FontAwesome
|
<TouchableOpacity
|
||||||
name="camera"
|
onPress={handleCameraType}
|
||||||
style={{ color: "#fff", fontSize: 40 }}
|
style={{
|
||||||
/>
|
alignSelf: "flex-end",
|
||||||
</TouchableOpacity>
|
alignItems: "center",
|
||||||
<TouchableOpacity
|
backgroundColor: "transparent",
|
||||||
onPress={() => {
|
}}
|
||||||
navigation.push("MediaCache");
|
>
|
||||||
}}
|
<MaterialCommunityIcons
|
||||||
style={{
|
name="camera-switch"
|
||||||
alignSelf: "flex-end",
|
style={{ color: "#fff", fontSize: 40 }}
|
||||||
alignItems: "center",
|
/>
|
||||||
backgroundColor: "transparent",
|
</TouchableOpacity>
|
||||||
}}
|
<TouchableOpacity
|
||||||
>
|
onPress={handleTakePicture}
|
||||||
<Ionicons
|
style={{
|
||||||
name="ios-photos"
|
alignSelf: "flex-end",
|
||||||
style={{ color: "#fff", fontSize: 40 }}
|
alignItems: "center",
|
||||||
/>
|
backgroundColor: "transparent",
|
||||||
</TouchableOpacity>
|
}}
|
||||||
</View>
|
>
|
||||||
|
<FontAwesome
|
||||||
|
name="camera"
|
||||||
|
style={{ color: "#fff", fontSize: 40 }}
|
||||||
|
/>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => {
|
||||||
|
navigation.push("MediaCache");
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
alignSelf: "flex-end",
|
||||||
|
alignItems: "center",
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name="ios-photos"
|
||||||
|
style={{ color: "#fff", fontSize: 40 }}
|
||||||
|
/>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</SafeAreaView>
|
||||||
</Camera>
|
</Camera>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(ScreenCamera);
|
||||||
|
|||||||
@@ -27,8 +27,10 @@ import ScreenSettingsComponent from "../screen-settings/screen-settings.componen
|
|||||||
import ScreenSignIn from "../screen-sign-in/screen-sign-in.component";
|
import ScreenSignIn from "../screen-sign-in/screen-sign-in.component";
|
||||||
import ScreenSplash from "../screen-splash/screen-splash.component";
|
import ScreenSplash from "../screen-splash/screen-splash.component";
|
||||||
import ScreenMediaCache from "../screen-media-cache/screen-media-cache.component";
|
import ScreenMediaCache from "../screen-media-cache/screen-media-cache.component";
|
||||||
|
import ScreenCameraJobSearch from "../screen-camera-job-search/screen-camera-job-search.component";
|
||||||
|
|
||||||
const JobStack = createStackNavigator();
|
const JobStack = createStackNavigator();
|
||||||
|
const CameraStack = createStackNavigator();
|
||||||
const MessagingStack = createStackNavigator();
|
const MessagingStack = createStackNavigator();
|
||||||
const BottomTabs = createBottomTabNavigator();
|
const BottomTabs = createBottomTabNavigator();
|
||||||
const Drawer = createDrawerNavigator();
|
const Drawer = createDrawerNavigator();
|
||||||
@@ -75,24 +77,23 @@ const JobStackNavigator = ({ navigation }) => (
|
|||||||
i18n.t("joblist.labels.detail"),
|
i18n.t("joblist.labels.detail"),
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<JobStack.Screen
|
|
||||||
name="JobCamera"
|
|
||||||
options={{ headerShown: false }}
|
|
||||||
component={ScreenCamera}
|
|
||||||
/>
|
|
||||||
<JobStack.Screen name="MediaCache" component={ScreenMediaCache} />
|
|
||||||
</JobStack.Navigator>
|
</JobStack.Navigator>
|
||||||
);
|
);
|
||||||
|
|
||||||
const CameraStackNavigator = ({ navigation }) => (
|
const CameraStackNavigator = ({ navigation }) => (
|
||||||
<JobStack.Navigator initialRouteName="TabCamera">
|
<CameraStack.Navigator initialRouteName="TabCamera">
|
||||||
<JobStack.Screen
|
<CameraStack.Screen
|
||||||
name="TabCamera"
|
name="TabCamera"
|
||||||
options={{ headerShown: false }}
|
options={{ headerShown: false }}
|
||||||
component={ScreenCamera}
|
component={ScreenCamera}
|
||||||
/>
|
/>
|
||||||
<JobStack.Screen name="MediaCache" component={ScreenMediaCache} />
|
<CameraStack.Screen
|
||||||
</JobStack.Navigator>
|
name="CameraJobSearch"
|
||||||
|
component={ScreenCameraJobSearch}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<CameraStack.Screen name="MediaCache" component={ScreenMediaCache} />
|
||||||
|
</CameraStack.Navigator>
|
||||||
);
|
);
|
||||||
const MessagingStackNavigator = ({ navigation }) => (
|
const MessagingStackNavigator = ({ navigation }) => (
|
||||||
<MessagingStack.Navigator>
|
<MessagingStack.Navigator>
|
||||||
|
|||||||
@@ -1,247 +1,47 @@
|
|||||||
// import React, { useEffect } from "react";
|
import * as FileSystem from "expo-file-system";
|
||||||
// import * as FileSystem from "expo-file-system";
|
import React, { useEffect, useState } from "react";
|
||||||
// import { Button, Image, View, Text } from "react-native";
|
import { SafeAreaView, Text } from "react-native";
|
||||||
// import * as ImagePicker from "expo-image-picker";
|
import { Button, Text as NBText } from "native-base";
|
||||||
// import Constants from "expo-constants";
|
export default function ScreenMediaCache() {
|
||||||
// import * as Permissions from "expo-permissions";
|
const [images, setImages] = useState([]);
|
||||||
|
useEffect(() => {
|
||||||
// export default function ScreenMediaCache() {
|
(async () => {
|
||||||
// FileSystem.readDirectoryAsync(FileSystem.documentDirectory).then((p) => {
|
setImages(
|
||||||
// console.log(p);
|
(
|
||||||
// });
|
await FileSystem.readDirectoryAsync(
|
||||||
|
FileSystem.documentDirectory + "photos"
|
||||||
// useEffect(() => {
|
)
|
||||||
// (async () => {
|
).map((f) => {
|
||||||
// if (Constants.platform.ios) {
|
return {
|
||||||
// const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
|
uri: FileSystem.documentDirectory + "photos/" + f,
|
||||||
// if (status !== "granted") {
|
dimensions: { width: 2142, height: 4224 },
|
||||||
// alert("Sorry, we need camera roll permissions to make this work!");
|
};
|
||||||
// }
|
})
|
||||||
// }
|
|
||||||
// })();
|
|
||||||
// }, []);
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <View>
|
|
||||||
// <Text>This is the media cache screen.</Text>
|
|
||||||
// <Button title="Pick an Image from Album" />
|
|
||||||
// {image && (
|
|
||||||
// <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />
|
|
||||||
// )}
|
|
||||||
// </View>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
import React, { Component } from "react";
|
|
||||||
import {
|
|
||||||
ActivityIndicator,
|
|
||||||
Button,
|
|
||||||
Clipboard,
|
|
||||||
Image,
|
|
||||||
Share,
|
|
||||||
StatusBar,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
TouchableOpacity,
|
|
||||||
View,
|
|
||||||
} from "react-native";
|
|
||||||
import { Constants } from "expo";
|
|
||||||
import * as Permissions from "expo-permissions";
|
|
||||||
import * as ImagePicker from "expo-image-picker";
|
|
||||||
export default class App extends Component {
|
|
||||||
state = {
|
|
||||||
image: null,
|
|
||||||
uploading: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let { image } = this.state;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={styles.container}>
|
|
||||||
<StatusBar barStyle="default" />
|
|
||||||
|
|
||||||
<Text style={styles.exampleText}>
|
|
||||||
Example: Upload ImagePicker result
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
onPress={this._pickImage}
|
|
||||||
title="Pick an image from camera roll"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button onPress={this._takePhoto} title="Take a photo" />
|
|
||||||
|
|
||||||
{this._maybeRenderImage()}
|
|
||||||
{this._maybeRenderUploadingOverlay()}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_maybeRenderUploadingOverlay = () => {
|
|
||||||
if (this.state.uploading) {
|
|
||||||
return (
|
|
||||||
<View style={[StyleSheet.absoluteFill, styles.maybeRenderUploading]}>
|
|
||||||
<ActivityIndicator color="#fff" size="large" />
|
|
||||||
</View>
|
|
||||||
);
|
);
|
||||||
}
|
})();
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
_maybeRenderImage = () => {
|
return (
|
||||||
let { image } = this.state;
|
<SafeAreaView style={{ display: "flex", flex: 1 }}>
|
||||||
|
<Text>This is the media cache screen.</Text>
|
||||||
if (!image) {
|
<Button
|
||||||
return;
|
block
|
||||||
}
|
onPress={async () => {
|
||||||
|
const fps = (
|
||||||
return (
|
await FileSystem.readDirectoryAsync(
|
||||||
<View style={styles.maybeRenderContainer}>
|
FileSystem.documentDirectory + "photos"
|
||||||
<View style={styles.maybeRenderImageContainer}>
|
)
|
||||||
<Image source={{ uri: image }} style={styles.maybeRenderImage} />
|
).map((f) => {
|
||||||
</View>
|
return FileSystem.documentDirectory + "photos/" + f;
|
||||||
|
});
|
||||||
<Text
|
const all = [];
|
||||||
onPress={this._copyToClipboard}
|
fps.forEach((f) => all.push(FileSystem.deleteAsync(f)));
|
||||||
onLongPress={this._share}
|
await Promise.all(all);
|
||||||
style={styles.maybeRenderImageText}
|
console.log("All photos deleted.");
|
||||||
>
|
}}
|
||||||
{image}
|
>
|
||||||
</Text>
|
<NBText>Delete all</NBText>
|
||||||
</View>
|
</Button>
|
||||||
);
|
</SafeAreaView>
|
||||||
};
|
);
|
||||||
|
|
||||||
_share = () => {
|
|
||||||
Share.share({
|
|
||||||
message: this.state.image,
|
|
||||||
title: "Check out this photo",
|
|
||||||
url: this.state.image,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
_copyToClipboard = () => {
|
|
||||||
Clipboard.setString(this.state.image);
|
|
||||||
alert("Copied image URL to clipboard");
|
|
||||||
};
|
|
||||||
|
|
||||||
_takePhoto = async () => {
|
|
||||||
const { status: cameraPerm } = await Permissions.askAsync(
|
|
||||||
Permissions.CAMERA
|
|
||||||
);
|
|
||||||
|
|
||||||
const { status: cameraRollPerm } = await Permissions.askAsync(
|
|
||||||
Permissions.CAMERA_ROLL
|
|
||||||
);
|
|
||||||
|
|
||||||
// only if user allows permission to camera AND camera roll
|
|
||||||
if (cameraPerm === "granted" && cameraRollPerm === "granted") {
|
|
||||||
let pickerResult = await ImagePicker.launchCameraAsync({
|
|
||||||
allowsMultipleSelection: true,
|
|
||||||
quality: 0.8,
|
|
||||||
//allowsEditing: true,
|
|
||||||
aspect: [4, 3],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!pickerResult.cancelled) {
|
|
||||||
this.setState({ image: pickerResult.uri });
|
|
||||||
}
|
|
||||||
|
|
||||||
this.uploadImageAsync(pickerResult.uri);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_pickImage = async () => {
|
|
||||||
const { status: cameraRollPerm } = await Permissions.askAsync(
|
|
||||||
Permissions.CAMERA_ROLL
|
|
||||||
);
|
|
||||||
|
|
||||||
// only if user allows permission to camera roll
|
|
||||||
if (cameraRollPerm === "granted") {
|
|
||||||
let pickerResult = await ImagePicker.launchImageLibraryAsync({
|
|
||||||
allowsEditing: true,
|
|
||||||
base64: true,
|
|
||||||
aspect: [4, 3],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!pickerResult.cancelled) {
|
|
||||||
this.setState({ image: pickerResult.uri });
|
|
||||||
}
|
|
||||||
|
|
||||||
this.uploadImageAsync(pickerResult.uri);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
uploadImageAsync(pictureuri) {
|
|
||||||
let apiUrl = "http://123.123.123.123/ABC";
|
|
||||||
|
|
||||||
var data = new FormData();
|
|
||||||
data.append("file", {
|
|
||||||
uri: pictureuri,
|
|
||||||
name: "file",
|
|
||||||
type: "image/jpg",
|
|
||||||
});
|
|
||||||
|
|
||||||
fetch(apiUrl, {
|
|
||||||
headers: {
|
|
||||||
Accept: "application/json",
|
|
||||||
"Content-Type": "multipart/form-data",
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
body: data,
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
console.log("succ ");
|
|
||||||
console.log(response);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log("err ");
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
alignItems: "center",
|
|
||||||
flex: 1,
|
|
||||||
justifyContent: "center",
|
|
||||||
},
|
|
||||||
exampleText: {
|
|
||||||
fontSize: 20,
|
|
||||||
marginBottom: 20,
|
|
||||||
marginHorizontal: 15,
|
|
||||||
textAlign: "center",
|
|
||||||
},
|
|
||||||
maybeRenderUploading: {
|
|
||||||
alignItems: "center",
|
|
||||||
backgroundColor: "rgba(0,0,0,0.4)",
|
|
||||||
justifyContent: "center",
|
|
||||||
},
|
|
||||||
maybeRenderContainer: {
|
|
||||||
borderRadius: 3,
|
|
||||||
elevation: 2,
|
|
||||||
marginTop: 30,
|
|
||||||
shadowColor: "rgba(0,0,0,1)",
|
|
||||||
shadowOpacity: 0.2,
|
|
||||||
shadowOffset: {
|
|
||||||
height: 4,
|
|
||||||
width: 4,
|
|
||||||
},
|
|
||||||
shadowRadius: 5,
|
|
||||||
width: 250,
|
|
||||||
},
|
|
||||||
maybeRenderImageContainer: {
|
|
||||||
borderTopLeftRadius: 3,
|
|
||||||
borderTopRightRadius: 3,
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
maybeRenderImage: {
|
|
||||||
height: 250,
|
|
||||||
width: 250,
|
|
||||||
},
|
|
||||||
maybeRenderImageText: {
|
|
||||||
paddingHorizontal: 10,
|
|
||||||
paddingVertical: 10,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|||||||
21
package-lock.json
generated
21
package-lock.json
generated
@@ -4024,6 +4024,22 @@
|
|||||||
"fontfaceobserver": "^2.1.0"
|
"fontfaceobserver": "^2.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"expo-image-picker": {
|
||||||
|
"version": "9.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/expo-image-picker/-/expo-image-picker-9.1.1.tgz",
|
||||||
|
"integrity": "sha512-Etz2OQhRflfx+xFbSdma8QLZsnV/yq0M/yqYlsi3/RLiWAQYM/D/VmRfDDPiG10gm+KX3Xb5iKplNjPrWeTuQg==",
|
||||||
|
"requires": {
|
||||||
|
"expo-permissions": "~9.3.0",
|
||||||
|
"uuid": "7.0.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"uuid": {
|
||||||
|
"version": "7.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.2.tgz",
|
||||||
|
"integrity": "sha512-vy9V/+pKG+5ZTYKf+VcphF5Oc6EFiu3W8Nv3P3zIh0EqVI80ZxOzuPfe9EHjkFNvf8+xuTHVeei4Drydlx4zjw=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"expo-keep-awake": {
|
"expo-keep-awake": {
|
||||||
"version": "8.3.0",
|
"version": "8.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-8.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-8.3.0.tgz",
|
||||||
@@ -4057,6 +4073,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/expo-location/-/expo-location-9.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/expo-location/-/expo-location-9.0.1.tgz",
|
||||||
"integrity": "sha512-yl4V2IelxrjG1h3nshkyILwghysNJvvEuR4Of0U7oYAsBrT0cq8NxFuaDemRvqt9Yb19wVFNMoVtYFNpthcqpQ=="
|
"integrity": "sha512-yl4V2IelxrjG1h3nshkyILwghysNJvvEuR4Of0U7oYAsBrT0cq8NxFuaDemRvqt9Yb19wVFNMoVtYFNpthcqpQ=="
|
||||||
},
|
},
|
||||||
|
"expo-media-library": {
|
||||||
|
"version": "9.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/expo-media-library/-/expo-media-library-9.2.1.tgz",
|
||||||
|
"integrity": "sha512-A9AAGI1200P0oULoXA7U7wQ91zgPWl9GWo5H9EQvVDHp1ABX8tf2qTOad6Y0KotHYWVMIyfsVXzVYAbjJ9LxPQ=="
|
||||||
|
},
|
||||||
"expo-permissions": {
|
"expo-permissions": {
|
||||||
"version": "9.3.0",
|
"version": "9.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/expo-permissions/-/expo-permissions-9.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/expo-permissions/-/expo-permissions-9.3.0.tgz",
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ export const setCameraJobId = (jobId) => ({
|
|||||||
payload: jobId,
|
payload: jobId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const setCameraJob = (job) => ({
|
||||||
|
type: AppActionTypes.SET_CAMERA_JOB,
|
||||||
|
payload: job,
|
||||||
|
});
|
||||||
|
|
||||||
export const documentUploadStart = (jobId) => ({
|
export const documentUploadStart = (jobId) => ({
|
||||||
type: AppActionTypes.DOCUMENT_UPLOAD_START,
|
type: AppActionTypes.DOCUMENT_UPLOAD_START,
|
||||||
payload: jobId,
|
payload: jobId,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import AppActionTypes from "./app.types";
|
|||||||
|
|
||||||
const INITIAL_STATE = {
|
const INITIAL_STATE = {
|
||||||
cameraJobId: null,
|
cameraJobId: null,
|
||||||
|
cameraJob: null,
|
||||||
documentUploadInProgress: null,
|
documentUploadInProgress: null,
|
||||||
documentUploadError: null,
|
documentUploadError: null,
|
||||||
};
|
};
|
||||||
@@ -13,6 +14,11 @@ const appReducer = (state = INITIAL_STATE, action) => {
|
|||||||
...state,
|
...state,
|
||||||
cameraJobId: action.payload,
|
cameraJobId: action.payload,
|
||||||
};
|
};
|
||||||
|
case AppActionTypes.SET_CAMERA_JOB:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
cameraJob: action.payload,
|
||||||
|
};
|
||||||
case AppActionTypes.DOCUMENT_UPLOAD_START:
|
case AppActionTypes.DOCUMENT_UPLOAD_START:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|||||||
@@ -4,13 +4,17 @@ const selectApp = (state) => state.app;
|
|||||||
|
|
||||||
export const selectCurrentCameraJobId = createSelector(
|
export const selectCurrentCameraJobId = createSelector(
|
||||||
[selectApp],
|
[selectApp],
|
||||||
(user) => app.cameraJobId
|
(app) => app.cameraJobId
|
||||||
|
);
|
||||||
|
export const selectCurrentCameraJob = createSelector(
|
||||||
|
[selectApp],
|
||||||
|
(app) => app.cameraJob
|
||||||
);
|
);
|
||||||
export const selectDocumentUploadInProgress = createSelector(
|
export const selectDocumentUploadInProgress = createSelector(
|
||||||
[selectApp],
|
[selectApp],
|
||||||
(user) => app.documentUploadInProgress
|
(app) => app.documentUploadInProgress
|
||||||
);
|
);
|
||||||
export const selectDocumentUploadError = createSelector(
|
export const selectDocumentUploadError = createSelector(
|
||||||
[selectApp],
|
[selectApp],
|
||||||
(user) => app.documentUploadError
|
(app) => app.documentUploadError
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const AppActionTypes = {
|
const AppActionTypes = {
|
||||||
SET_CAMERA_JOB_ID: "SET_CAMERA_JOB_ID",
|
SET_CAMERA_JOB_ID: "SET_CAMERA_JOB_ID",
|
||||||
|
SET_CAMERA_JOB: "SET_CAMERA_JOB",
|
||||||
DOCUMENT_UPLOAD_START: "DOCUMENT_UPLOAD_START",
|
DOCUMENT_UPLOAD_START: "DOCUMENT_UPLOAD_START",
|
||||||
DOCUMNET_UPLOAD_SUCCESS: "DOCUMNET_UPLOAD_SUCCESS",
|
DOCUMNET_UPLOAD_SUCCESS: "DOCUMNET_UPLOAD_SUCCESS",
|
||||||
DOCUMENT_UPLOAD_FAILURE: "DOCUMENT_UPLOAD_FAILURE",
|
DOCUMENT_UPLOAD_FAILURE: "DOCUMENT_UPLOAD_FAILURE",
|
||||||
|
|||||||
Reference in New Issue
Block a user