| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import React from "react";
- import { Button, Layout, Icon } from "@ui-kitten/components";
- import { useModel } from "flooks";
- import { Linking } from "expo";
- import * as ImagePicker from "expo-image-picker";
- import { Image } from "react-native";
- import * as FileSystem from "expo-file-system";
- export default function UpLoadImage(props) {
- const { connect } = useModel("wordsModel");
- const { httpPost } = useModel("httpModel", true);
- const renderPulseIcon = (props) => <Icon {...props} name='plus-outline' />;
- return (
- <>
- <Button
- style={[props.style]}
- appearance='imageButton'
- onPress={() => {
- _pickImage().then((img) => {
- httpPost("/upload/base64", {
- base64: img,
- }).then((res) => {
- props.changeIcon(res);
- });
- });
- }}
- accessoryLeft={(imgprops) => {
- console.log(imgprops);
- console.log(props);
- if (props.value && props.value != " ") {
- return (
- <Image
- style={{
- width: "100%",
- height: "100%",
- }}
- source={props.value}
- />
- );
- } else {
- return renderPulseIcon(imgprops);
- }
- }}
- />
- </>
- );
- }
- const getPermissionAsync = async () => {
- if (Constants.platform.ios) {
- const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
- if (status !== "granted") {
- alert("Sorry, we need camera roll permissions to make this work!");
- }
- }
- };
- const _pickImage = () => {
- return new Promise(async (resolve, reject) => {
- try {
- let permissionResult = await ImagePicker.requestCameraRollPermissionsAsync();
- if (permissionResult.granted === false) {
- reject("notAllod");
- } else {
- let result = await ImagePicker.launchImageLibraryAsync({
- mediaTypes: ImagePicker.MediaTypeOptions.Images,
- allowsEditing: true,
- aspect: [1, 1],
- quality: 1,
- });
- if (!result.cancelled) {
- // let file = await FileSystem.readAsStringAsync(result.uri);
- resolve(result.uri);
- }
- }
- } catch (e) {
- reject(e);
- }
- });
- };
|