import { Feather } from '@expo/vector-icons' import React, { useCallback, useEffect, useState } from 'react' import { Alert, Keyboard, KeyboardAvoidingView, Pressable, StyleSheet, Text, TextInput, View } from 'react-native' import { createNativeStackNavigator } from 'react-native-screens/native-stack' import Autolinker from 'src/modules/autolinker' import { useNavigation } from '@react-navigation/native' const Stack = createNativeStackNavigator() const PostTootMain = () => { const [viewHeight, setViewHeight] = useState(0) const [keyboardHeight, setKeyboardHeight] = useState(0) useEffect(() => { Keyboard.addListener('keyboardDidShow', _keyboardDidShow) Keyboard.addListener('keyboardDidHide', _keyboardDidHide) // cleanup function return () => { Keyboard.removeListener('keyboardDidShow', _keyboardDidShow) Keyboard.removeListener('keyboardDidHide', _keyboardDidHide) } }, []) const _keyboardDidShow = (props: any) => { setKeyboardHeight(props.endCoordinates.height) } const _keyboardDidHide = () => { setKeyboardHeight(0) } const [charCount, setCharCount] = useState(0) const [formattedText, setFormattedText] = useState() let prevTags = [] const onChangeText = useCallback(content => { const tags: string[] = [] Autolinker.link(content, { email: true, phone: false, mention: 'mastodon', hashtag: 'twitter', replaceFn: props => { const tag = props.getMatchedText() tags.push(tag) return tag } }) prevTags = tags let _content = content const children = [] tags.forEach(tag => { const parts = _content.split(tag) children.push(parts.shift()) children.push( {tag} ) _content = parts.join(tag) }) children.push(_content) setFormattedText(React.createElement(Text, null, children)) setCharCount(content.length) }, []) return ( setViewHeight(nativeEvent.layout.height)} > {formattedText} Keyboard.dismiss()}> {charCount} ) } const PostToot: React.FC = () => { const navigation = useNavigation() return ( ( Alert.alert('确认取消编辑?', '', [ { text: '继续编辑', style: 'cancel' }, { text: '退出编辑', style: 'destructive', onPress: () => navigation.goBack() } ]) } > 退出编辑 ), headerCenter: () => <>, headerRight: () => ( 发嘟嘟 ) }} /> ) } const styles = StyleSheet.create({ main: { flex: 1 }, textInput: { flex: 1, backgroundColor: 'gray' }, additions: { height: 44, backgroundColor: 'red', flexDirection: 'row' } }) export default PostToot