-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
100 lines (91 loc) · 2.38 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { StatusBar } from "expo-status-bar";
import React, { useState, useEffect } from "react";
import { StyleSheet, SafeAreaView, Platform } from "react-native";
import * as ImagePicker from "expo-image-picker";
import { Editor } from "./components/Editor";
import { Section } from "./types/section";
const INITIAL_SECTIONS: Section[] = [
{
type: "header",
data: "お知らせ",
},
{
type: "body",
data:
"いつもxxをご利用いただきありがとうございます。お客様にお知らせです。",
},
{
type: "image",
data:
"https://i.picsum.photos/id/10/2500/1667.jpg?hmac=J04WWC_ebchx3WwzbM-Z4_KC_LeLBWr5LZMaAkWkF68",
},
];
export default function App() {
const [sections, setSections] = useState<Section[]>(INITIAL_SECTIONS);
useEffect(() => {
(async () => {
if (Platform.OS !== "web") {
const {
status,
} = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (status !== "granted") {
alert("Sorry, we need camera roll permissions to make this work!");
}
}
})();
}, []);
const onChangeText = (index: number, text: string) => {
const newSections = sections.map((section, _index) => {
if (_index === index) {
return {
...section,
data: text,
};
} else {
return section;
}
});
//console.log(newSections);
setSections(newSections);
};
const onPickImage = (uri: string) => {
const section: Section = {
type: "image",
data: uri,
};
setSections([...sections, section]);
};
const onPressAddText = () => {
const section: Section = {
type: "body",
data: "",
};
setSections([...sections, section]);
};
const onPressDelete = (index: number) => {
console.log(index);
const newSections = sections.filter((section, _index) => {
return _index !== index;
});
//console.log(newSections);
setSections(newSections);
};
return (
<SafeAreaView style={styles.container}>
<Editor
sections={sections}
onChangeText={onChangeText}
onPickImage={onPickImage}
onPressAddText={onPressAddText}
onPressDelete={onPressDelete}
/>
<StatusBar style="auto" />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
},
});