-
Notifications
You must be signed in to change notification settings - Fork 5
/
EditorScreen.tsx
143 lines (130 loc) · 3.66 KB
/
EditorScreen.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import * as React from "react";
import {
Dimensions,
Image,
ImageURISource,
Pressable,
SafeAreaView,
StatusBar,
StyleSheet,
Text,
View,
} from "react-native";
import EditBox, { Adjustments, RotationAngles } from "./EditBox";
interface EditScreenProps {
onCancel?: () => void;
onDone: (adjustments: Adjustments) => void;
source: ImageURISource & { height: number; width: number };
useBackgroundCover?: boolean;
}
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
const PADDING_HORIZONTAL = 15;
const BOX_WIDTH = SCREEN_WIDTH - PADDING_HORIZONTAL * 2;
export default function EditScreen({ onCancel, onDone, source, useBackgroundCover = true }: EditScreenProps) {
const editBoxRef = React.useRef<React.ElementRef<typeof EditBox>>(null);
const rotation = React.useRef<number>(0);
const handleOnCancel = () => {
onCancel?.();
};
const handleOnDone = () => {
if (!editBoxRef.current) return;
onDone?.(editBoxRef.current.calculateAdjustments());
};
const handleOnFlip = () => {
editBoxRef.current?.flip();
};
const handleOnReset = () => {
editBoxRef.current?.reset();
rotation.current = 0;
};
const handleOnRotate = () => {
const newValue = (rotation.current + 90) % 360;
editBoxRef.current?.rotate(newValue as RotationAngles);
rotation.current = newValue;
};
return (
<View style={styles.page}>
{useBackgroundCover && (
<Image blurRadius={28} resizeMode="cover" source={source} style={styles.backgroundCover} />
)}
<SafeAreaView style={styles.safeArea}>
<StatusBar barStyle="light-content" />
<View style={styles.safeArea}>
<View style={styles.content}>
<EditBox ref={editBoxRef} maxHeight={SCREEN_HEIGHT * 0.7} maxWidth={BOX_WIDTH} source={{ ...source }} />
</View>
<View style={styles.primaryButtons}>
<Pressable onPress={handleOnRotate}>
<Text style={styles.resetText}>Rotate</Text>
</Pressable>
<Pressable onPress={handleOnFlip}>
<Text style={styles.resetText}>Flip</Text>
</Pressable>
<Pressable onPress={handleOnReset}>
<Text style={styles.resetText}>Reset</Text>
</Pressable>
</View>
<View style={styles.bottomButtons}>
{undefined !== onCancel ? (
<Pressable onPress={handleOnCancel}>
<Text style={styles.bottomButtonText}>Cancel</Text>
</Pressable>
) : (
<View />
)}
<Pressable onPress={handleOnDone}>
<Text style={styles.bottomButtonText}>Done</Text>
</Pressable>
</View>
</View>
</SafeAreaView>
</View>
);
}
const styles = StyleSheet.create({
backgroundCover: {
...StyleSheet.absoluteFillObject,
bottom: 50,
width: SCREEN_WIDTH,
height: "95%",
opacity: 0.1,
},
bottomButtons: {
backgroundColor: "rgb(56, 56, 56)",
flexDirection: "row",
justifyContent: "space-between",
paddingHorizontal: PADDING_HORIZONTAL,
paddingVertical: 10,
},
bottomButtonText: {
color: "white",
fontSize: 16,
fontWeight: "700",
},
container: {
flex: 1,
},
content: {
alignItems: "center",
justifyContent: "center",
flex: 1,
},
primaryButtons: {
alignItems: "center",
flexDirection: "row",
justifyContent: "space-between",
paddingHorizontal: PADDING_HORIZONTAL,
paddingBottom: 10,
},
resetText: {
color: "white",
fontSize: 16,
},
page: {
backgroundColor: "rgb(56, 56, 56)",
flex: 1,
},
safeArea: {
flex: 1,
},
});