diff --git a/apps/mobile/src/components/GeneralSheet/index.js b/apps/mobile/src/components/GeneralSheet/index.js index acdf6d0fc..987a5f149 100644 --- a/apps/mobile/src/components/GeneralSheet/index.js +++ b/apps/mobile/src/components/GeneralSheet/index.js @@ -10,6 +10,10 @@ import SheetWrapper from '../Sheet'; import {Button} from '../Button'; import Heading from '../Typography/Heading'; import Paragraph from '../Typography/Paragraph'; +import tiny from '../../views/Editor/tiny/tiny'; +import {EditorWebView} from '../../views/Editor/Functions'; +import {editing} from '../../utils'; +import {reFocusEditor} from '../../views/Editor/tiny/toolbar/constants'; const GeneralSheet = ({context}) => { const [state] = useTracked(); @@ -17,6 +21,10 @@ const GeneralSheet = ({context}) => { const [visible, setVisible] = useState(false); const [dialogData, setDialogData] = useState(null); const actionSheetRef = useRef(); + const editor = useRef({ + refocus: false + }); + useEffect(() => { eSubscribeEvent(eOpenProgressDialog, open); eSubscribeEvent(eCloseProgressDialog, close); @@ -35,10 +43,35 @@ const GeneralSheet = ({context}) => { } setDialogData(data); setVisible(true); - await sleep(1); - actionSheetRef.current?.setModalVisible(true); + if (data.editor) { + editor.current.refocus = false; + if (editing.keyboardState) { + tiny.call(EditorWebView, tiny.cacheRange); + tiny.call(EditorWebView, tiny.blur); + console.log('here'); + editor.current.refocus = true; + } + } }; + useEffect(() => { + (async () => { + if (visible) { + if (dialogData.editor) await sleep(100); + actionSheetRef.current?.setModalVisible(true); + return; + } else { + if (editor.current.refocus) { + editing.isFocused = true; + await reFocusEditor(); + tiny.call(EditorWebView, tiny.restoreRange); + tiny.call(EditorWebView, tiny.clearRange); + editor.current.refocus = false; + } + } + })(); + }, [visible]); + const close = ctx => { if ((ctx && !context) || (ctx && ctx !== context)) { return; diff --git a/apps/mobile/src/views/Editor/TableCellProperties.js b/apps/mobile/src/views/Editor/TableCellProperties.js index 44bc0710f..04dbb0e1f 100644 --- a/apps/mobile/src/views/Editor/TableCellProperties.js +++ b/apps/mobile/src/views/Editor/TableCellProperties.js @@ -1,26 +1,23 @@ -import React, {useEffect, useState} from 'react'; -import {View} from 'react-native'; -import {ScrollView} from 'react-native-gesture-handler'; -import {ActionIcon} from '../../components/ActionIcon'; -import {Button} from '../../components/Button'; -import {PressableButton} from '../../components/PressableButton'; +import React, { useEffect, useState } from 'react'; +import { View } from 'react-native'; +import { ScrollView } from 'react-native-gesture-handler'; +import { ActionIcon } from '../../components/ActionIcon'; +import { Button } from '../../components/Button'; import Heading from '../../components/Typography/Heading'; import Paragraph from '../../components/Typography/Paragraph'; -import {useTracked} from '../../provider'; +import { useTracked } from '../../provider'; import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent, presentSheet } from '../../services/EventManager'; -import { editing } from '../../utils'; import layoutmanager from '../../utils/layout-manager'; -import {SIZE} from '../../utils/SizeUtils'; -import { sleep } from '../../utils/TimeUtils'; -import {EditorWebView} from './Functions'; +import { SIZE } from '../../utils/SizeUtils'; +import { EditorWebView } from './Functions'; import tiny from './tiny/tiny'; import ColorItem from './tiny/toolbar/coloritem'; -import {editor_colors, rgbToHex} from './tiny/toolbar/constants'; +import { editor_colors, rgbToHex } from './tiny/toolbar/constants'; export const TableCellProperties = ({data}) => { const [state] = useTracked(); @@ -256,24 +253,14 @@ export const TableCellProperties = ({data}) => { }; TableCellProperties.isPresented = false; TableCellProperties.present = async data => { - eSendEvent('updaterow', data); - if (TableCellProperties.isPresented) return; - let refocus = false; - if (editing.keyboardState) { - tiny.call(EditorWebView, tiny.cacheRange); - tiny.call(EditorWebView, tiny.blur); - refocus = true; - } - await sleep(100) + eSendEvent('updatecell', data); + if (TableCellProperties.isPresented) return; TableCellProperties.isPresented = true; presentSheet({ component: , onClose: () => { TableCellProperties.isPresented = false; - if (!refocus) return; - tiny.call(EditorWebView, tiny.focusEditor); - tiny.call(EditorWebView, tiny.restoreRange); - tiny.call(EditorWebView, tiny.clearRange); - } + }, + editor:true }); }; diff --git a/apps/mobile/src/views/Editor/TableRowProperties.js b/apps/mobile/src/views/Editor/TableRowProperties.js index e375052eb..38d099a9c 100644 --- a/apps/mobile/src/views/Editor/TableRowProperties.js +++ b/apps/mobile/src/views/Editor/TableRowProperties.js @@ -1,18 +1,21 @@ -import React, {useEffect, useState} from 'react'; -import {View} from 'react-native'; -import {ScrollView} from 'react-native-gesture-handler'; -import {Button} from '../../components/Button'; +import React, { useEffect, useState } from 'react'; +import { View } from 'react-native'; +import { ScrollView } from 'react-native-gesture-handler'; +import { Button } from '../../components/Button'; import Heading from '../../components/Typography/Heading'; -import {useTracked} from '../../provider'; -import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent, presentSheet} from '../../services/EventManager'; -import { editing } from '../../utils'; +import { useTracked } from '../../provider'; +import { + eSendEvent, + eSubscribeEvent, + eUnSubscribeEvent, + presentSheet +} from '../../services/EventManager'; import layoutmanager from '../../utils/layout-manager'; -import {SIZE} from '../../utils/SizeUtils'; -import { sleep } from '../../utils/TimeUtils'; -import {EditorWebView} from './Functions'; +import { SIZE } from '../../utils/SizeUtils'; +import { EditorWebView } from './Functions'; import tiny from './tiny/tiny'; import ColorItem from './tiny/toolbar/coloritem'; -import {editor_colors, rgbToHex} from './tiny/toolbar/constants'; +import { editor_colors, rgbToHex } from './tiny/toolbar/constants'; export const TableRowProperties = ({data}) => { const [state] = useTracked(); @@ -172,24 +175,15 @@ export const TableRowProperties = ({data}) => { }; TableRowProperties.isPresented = false; TableRowProperties.present = async data => { - eSendEvent('updatecell', data); + eSendEvent('updaterow', data); if (TableRowProperties.isPresented) return; - let refocus = false; - if (editing.keyboardState) { - tiny.call(EditorWebView,tiny.cacheRange); - tiny.call(EditorWebView,tiny.blur); - refocus = true; - } - await sleep(100) + TableRowProperties.isPresented = true; presentSheet({ component: , onClose: () => { TableRowProperties.isPresented = false; - if (!refocus) return; - tiny.call(EditorWebView,tiny.focusEditor); - tiny.call(EditorWebView,tiny.restoreRange); - tiny.call(EditorWebView,tiny.clearRange); - } + }, + editor: true }); };