This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Editor.tsx
53 lines (50 loc) · 1.9 KB
/
Editor.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
import React from 'react'
import { View, KeyboardAvoidingView, SafeAreaView, Platform } from 'react-native'
import {
Typer,
Toolbar,
DocumentControlAction,
buildVectorIconControlSpec,
useBridge,
useDocument
} from '@typeskill/typer'
import { MaterialCommunityIcons } from '@expo/vector-icons'
import { soberTheme, ICON_SIZE, ICON_INACTIVE_COLOR, ICON_ACTIVE_COLOR, SPACING } from './styles'
function buildMaterialControlSpec(actionType: DocumentControlAction, name: string) {
return buildVectorIconControlSpec(MaterialCommunityIcons as any, actionType, name)
}
const toolbarLayout: Toolbar.Layout = [
buildMaterialControlSpec(DocumentControlAction.SELECT_TEXT_BOLD, 'format-bold'),
buildMaterialControlSpec(DocumentControlAction.SELECT_TEXT_ITALIC, 'format-italic'),
buildMaterialControlSpec(DocumentControlAction.SELECT_TEXT_UNDERLINE, 'format-underline'),
buildMaterialControlSpec(DocumentControlAction.SELECT_TEXT_STRIKETHROUGH, 'format-strikethrough-variant'),
]
export function Editor() {
const [document, setDocument] = useDocument()
const bridge = useBridge()
return (
<SafeAreaView style={soberTheme.rootContainer}>
<KeyboardAvoidingView behavior={Platform.select({ ios: 'padding' })} style={soberTheme.flex} enabled>
<View style={soberTheme.typerContainer}>
<Typer
document={document}
spacing={SPACING}
onDocumentUpdate={setDocument}
textStyle={soberTheme.textStyle}
bridge={bridge}
maxMediaBlockHeight={300}
/>
</View>
<Toolbar
iconSize={ICON_SIZE}
activeButtonColor={ICON_ACTIVE_COLOR}
inactiveButtonColor={ICON_INACTIVE_COLOR}
document={document}
layout={toolbarLayout}
contentContainerStyle={soberTheme.toolbarContainer}
bridge={bridge}
/>
</KeyboardAvoidingView>
</SafeAreaView>
)
}