Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

hide keyboard accessory view in webview

ammarahm-ed1fed84556279
diff --git a/apps/mobile/src/utils/useKeyboard.ts b/apps/mobile/src/utils/useKeyboard.ts
new file mode 100644
index 000000000..cd9e7e4eb
--- /dev/null
+++ b/apps/mobile/src/utils/useKeyboard.ts
@@ -0,0 +1,61 @@
+import {useEffect, useState} from 'react'
+import {Keyboard, KeyboardEventListener, ScreenRect} from 'react-native'
+
+const emptyCoordinates = Object.freeze({
+ screenX: 0,
+ screenY: 0,
+ width: 0,
+ height: 0,
+})
+const initialValue = {
+ start: emptyCoordinates,
+ end: emptyCoordinates,
+}
+
+export function useKeyboard() {
+ const [shown, setShown] = useState(false)
+ const [coordinates, setCoordinates] = useState<{
+ start: undefined | ScreenRect
+ end: ScreenRect
+ }>(initialValue)
+ const [keyboardHeight, setKeyboardHeight] = useState<number>(0)
+
+ const handleKeyboardWillShow: KeyboardEventListener = (e) => {
+ setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
+ }
+ const handleKeyboardDidShow: KeyboardEventListener = (e) => {
+ setShown(true)
+ setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
+ setKeyboardHeight(e.endCoordinates.height)
+ }
+ const handleKeyboardWillHide: KeyboardEventListener = (e) => {
+ setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
+ }
+ const handleKeyboardDidHide: KeyboardEventListener = (e) => {
+ setShown(false)
+ if (e) {
+ setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
+ } else {
+ setCoordinates(initialValue)
+ setKeyboardHeight(0)
+ }
+ }
+
+ useEffect(() => {
+ const subscriptions = [
+ Keyboard.addListener('keyboardWillShow', handleKeyboardWillShow),
+ Keyboard.addListener('keyboardDidShow', handleKeyboardDidShow),
+ Keyboard.addListener('keyboardWillHide', handleKeyboardWillHide),
+ Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide),
+ ]
+
+ return () => {
+ subscriptions.forEach((subscription) => subscription.remove())
+ }
+ }, [])
+ return {
+ keyboardShown: shown,
+ coordinates,
+ keyboardHeight,
+ }
+}
\ No newline at end of file
diff --git a/apps/mobile/src/views/Editor/HistoryComponent.js b/apps/mobile/src/views/Editor/HistoryComponent.js
index 9c5a46044..2e67cbe4e 100644
--- a/apps/mobile/src/views/Editor/HistoryComponent.js
+++ b/apps/mobile/src/views/Editor/HistoryComponent.js
@@ -1,11 +1,12 @@
-import React, {useEffect, useState} from 'react';
-import {Platform, View} from 'react-native';
-import {ActionIcon} from '../../components/ActionIcon';
-import {useTracked} from '../../provider';
-import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
-import {SIZE} from '../../utils/SizeUtils';
-import {EditorWebView, post} from './Functions';
-import tiny, {safeKeyboardDismiss} from './tiny/tiny';
+import React, { useEffect, useState } from 'react';
+import { Platform, View } from 'react-native';
+import { ActionIcon } from '../../components/ActionIcon';
+import { useTracked } from '../../provider';
+import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';
+import { SIZE } from '../../utils/SizeUtils';
+import { useKeyboard } from '../../utils/use-keyboard';
+import { EditorWebView } from './Functions';
+import tiny, { safeKeyboardDismiss } from './tiny/tiny';
const HistoryComponent = () => {
const [state] = useTracked();
@@ -14,7 +15,7 @@ const HistoryComponent = () => {
undo: false,
redo: false
});
-
+ const keyboard = useKeyboard();
const onHistoryChange = data => {
setHistoryState(data);
@@ -35,6 +36,21 @@ const HistoryComponent = () => {
height: 40,
marginRight: 5
}}>
+ {Platform.OS === 'ios' && keyboard.keyboardShown ? (
+ <ActionIcon
+ name="keyboard-close"
+ color={colors.pri}
+ size={SIZE.lg}
+ customStyle={{
+ width: 35,
+ height: 35
+ }}
+ onPress={() => {
+ safeKeyboardDismiss();
+ }}
+ />
+ ) : null}
+
<ActionIcon
name="undo-variant"
disabled={!historyState.undo}
@@ -63,23 +79,6 @@ const HistoryComponent = () => {
tiny.call(EditorWebView, tiny.redo);
}}
/>
-{/*
- {Platform.OS === 'ios' ? (
- <ActionIcon
- name="keyboard-close"
- disabled={!historyState.undo}
- color={colors.pri}
- size={SIZE.lg}
- customStyle={{
- width: 35,
- height: 35
- }}
- onPress={() => {
- safeKeyboardDismiss();
- }}
- />
- ) : null} */}
-
</View>
);
};
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index a39e56179..c5fdec182 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -1,5 +1,6 @@
import React, {useEffect, useState} from 'react';
import {Platform, View} from 'react-native';
+import { TextInput } from 'react-native-gesture-handler';
import WebView from 'react-native-webview';
import {notesnook} from '../../../e2e/test.ids';
import {useEditorStore, useUserStore} from '../../provider/stores';
@@ -115,6 +116,7 @@ const Editor = React.memo(
scalesPageToFit={true}
renderLoading={() => <View />}
startInLoadingState
+ hideKeyboardAccessoryView={true}
allowingReadAccessToURL={Platform.OS === 'android' ? true : null}
allowFileAccessFromFileURLs={true}
allowUniversalAccessFromFileURLs={true}
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/item.js b/apps/mobile/src/views/Editor/tiny/toolbar/item.js
index f5b8f4434..6a2976f77 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/item.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/item.js
@@ -392,7 +392,7 @@ const ToolbarItem = ({
/>
) : format === 'fontsize' ? (
<Paragraph
- size={SIZE.sm - 1}
+ size={13}
color={selected ? colors.accent : colors.pri}>
{formatValue || currentText || '12pt'}
</Paragraph>
@@ -408,7 +408,7 @@ const ToolbarItem = ({
: formatValue
: 'OpenSans-Regular'
}}
- size={SIZE.sm - 1}>
+ size={13}>
{currentText || text}
</Paragraph>
) : (