Skip to content

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

fix toolbar bugs

ammarahm-ed8c2ac84ba954
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/group.js b/apps/mobile/src/views/Editor/tiny/toolbar/group.js
index 309c19673..fd6eb3e4b 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/group.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/group.js
@@ -13,10 +13,12 @@ const ToolbarGroup = ({group}) => {
borderRadius: 0,
flexDirection: 'row',
alignItems: 'center',
- paddingRight: 12,
- marginRight:12,
- borderRightWidth:1,
- borderRightColor:colors.nav
+ marginRight:6,
+ backgroundColor:colors.bg,
+ borderTopRightRadius:5,
+ borderTopLeftRadius:5,
+ marginTop:5,
+ overflow:"hidden"
}}>
{group.map((item) => (
<ToolbarItem
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/index.js b/apps/mobile/src/views/Editor/tiny/toolbar/index.js
index d96641bdf..f35d66f46 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/index.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/index.js
@@ -3,6 +3,7 @@ import {View} from 'react-native';
import {ScrollView} from 'react-native';
import {useTracked} from '../../../../provider';
import {eSendEvent} from '../../../../services/EventManager';
+import { getElevation } from '../../../../utils';
import {TOOLBAR_CONFIG} from './config';
import {properties, toolbarRef} from './constants';
import ToolbarGroup from './group';
@@ -34,12 +35,14 @@ const EditorToolbar = React.memo(
width: '100%',
maxWidth: '100%',
minHeight: 50,
- borderTopWidth: 1,
- borderTopColor: colors.nav,
- paddingLeft: 12,
+ paddingLeft: 6,
+ backgroundColor:colors.nav,
+ borderTopRightRadius:5,
+ borderTopLeftRadius:5,
+ zIndex:11
}}
onScrollBeginDrag={() => {
- eSendEvent('showTooltip');
+ //eSendEvent('showTooltip');
}}
keyboardShouldPersistTaps="always"
keyboardDismissMode="none"
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/item.js b/apps/mobile/src/views/Editor/tiny/toolbar/item.js
index 5e666eb52..27e98cebf 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/item.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/item.js
@@ -56,24 +56,22 @@ const ToolbarItem = ({
}, []);
useEffect(() => {
- console.log('called')
onSelectionChange(properties.selection);
}, []);
const checkForChanges = (data) => {
properties.selection = data;
let formats = Object.keys(data);
-
- if (!data['link'] && type === "tooltip") {
- eSendEvent('showTooltip');
+ if (!data['link'] && type === 'tooltip') {
+ if (editing.tooltip) {
+ eSendEvent('showTooltip');
+ }
}
if (format === 'header' && type === 'tooltip') {
let keys = group.map((i) => i.format);
keys.forEach((k) => {
if (formats.includes(k)) {
- console.log(group.find((e) => e.format === k).text);
setCurrentText(group.find((e) => e.format === k).text);
-
setSelected(false);
}
});
@@ -101,7 +99,6 @@ const ToolbarItem = ({
}
if (format === 'link') {
- console.log(format, data[format]);
properties.selection = data;
properties.pauseSelectionChange = true;
eSendEvent('showTooltip', {
@@ -204,7 +201,7 @@ const ToolbarItem = ({
if (editing.tooltip === format && !formatValue) {
focusEditor(format);
eSendEvent('showTooltip');
- editing.tooltip = null;
+
properties.pauseSelectionChange = false;
return;
}
@@ -222,7 +219,7 @@ const ToolbarItem = ({
}
if (type === 'tooltip') {
- editing.tooltip = format;
+ properties.pauseSelectionChange = true;
eSendEvent('showTooltip', {
data: group,
title: format,
@@ -254,12 +251,13 @@ const ToolbarItem = ({
if (format === 'pre') {
if (selected) {
- formatSelection(`tinymce.activeEditor.execCommand("mceInsertNewLine", false, { shiftKey: true });`);
+ formatSelection(
+ `tinymce.activeEditor.execCommand("mceInsertNewLine", false, { shiftKey: true });`,
+ );
focusEditor(format);
- editing.tooltip = null;
return;
} else {
- value = "add";
+ value = 'add';
}
}
@@ -276,10 +274,7 @@ const ToolbarItem = ({
};
return (
- <View
- style={{
- marginHorizontal: 5,
- }}>
+ <View>
<PressableButton
type={selected ? 'shade' : 'transparent'}
customColor={selected && color}
@@ -294,11 +289,8 @@ const ToolbarItem = ({
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
- height: 40,
- minWidth: 40,
- borderRadius: 5,
- marginTop: 5,
- marginBottom: 5,
+ height: 50,
+ minWidth: 60,
}}>
{type === 'tooltip' && (
<ToolbarItemPin format={format} color={selected && color} />
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/itempin.js b/apps/mobile/src/views/Editor/tiny/toolbar/itempin.js
index 53e6b6ad5..9a7e4384b 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/itempin.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/itempin.js
@@ -1,44 +1,69 @@
-import React, { useEffect, useState } from 'react';
-import { View } from 'react-native';
-import { eSubscribeEvent, eUnSubscribeEvent } from '../../../../services/EventManager';
-import { useTracked } from '../../../../provider';
-
+import React, {useEffect, useState} from 'react';
+import {View} from 'react-native';
+import {
+ eSubscribeEvent,
+ eUnSubscribeEvent,
+} from '../../../../services/EventManager';
+import {useTracked} from '../../../../provider';
+import Animated, {Easing, timing, useValue} from 'react-native-reanimated';
+import {sleep} from '../../../../utils/TimeUtils';
const ToolbarItemPin = ({format, color}) => {
- const [state] = useTracked();
- const {colors} = state;
- const [visible, setVisible] = useState(false);
-
- useEffect(() => {
- eSubscribeEvent('showTooltip', show);
- return () => {
- eUnSubscribeEvent('showTooltip', show);
- };
- }, []);
-
- const show = (data) => {
- if (data?.title === format) {
- setVisible(true);
- } else {
- setVisible(false);
- }
- };
-
- return (
- visible && (
- <View
- style={{
- width: 10,
- height: 10,
- backgroundColor: color || colors.accent,
- borderRadius: 100,
- position: 'absolute',
- top: 0,
- top: -10,
- }}
- />
- )
- );
+ const [state] = useTracked();
+ const {colors} = state;
+ const [visible, setVisible] = useState(false);
+ let scale = useValue(0);
+ useEffect(() => {
+ eSubscribeEvent('showTooltip', show);
+ return () => {
+ eUnSubscribeEvent('showTooltip', show);
+ };
+ }, []);
+
+ let animating = false;
+ async function animate(val, time = 200) {
+ if (animating) return;
+ animating = true;
+ timing(scale, {
+ toValue: val,
+ duration: time,
+ easing: Easing.in(Easing.ease),
+ }).start(async () => {
+ await sleep(time);
+ animating = false;
+ });
+ }
+
+ const show = async (data) => {
+ if (data?.title === format) {
+ setVisible(true);
+ await sleep(5);
+ animate(1, 150);
+ } else {
+ animate(0, 150);
+ await sleep(100);
+ setVisible(false);
+ }
};
+
+ return (
+ visible && (
+ <Animated.View
+ style={{
+ width: '100%',
+ height: 3,
+ backgroundColor: color || colors.accent,
+ position: 'absolute',
+ top: 0,
+ transform: [
+ {
+ scale: scale,
+ },
+ ],
+ }}
+ />
+ )
+ );
+};
- export default ToolbarItemPin
\ No newline at end of file
+export default ToolbarItemPin;
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
index af65602ab..a5baa304f 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
@@ -6,11 +6,17 @@ import Input from '../../../../components/Input';
import {useTracked} from '../../../../provider';
import {editing} from '../../../../utils';
import {execCommands} from './commands';
-import {focusEditor, formatSelection, INPUT_MODE, properties} from './constants';
+import {
+ focusEditor,
+ formatSelection,
+ INPUT_MODE,
+ properties,
+} from './constants';
import LinkPreview from './linkpreview';
import tiny from '../tiny';
-import { EditorWebView } from '../../Functions';
-import { openLinkInBrowser } from '../../../../utils/functions';
+import {EditorWebView} from '../../Functions';
+import {openLinkInBrowser} from '../../../../utils/functions';
+import {SIZE} from '../../../../utils/SizeUtils';
let inputValue = null;
@@ -113,7 +119,7 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
title="Save"
onPress={onSubmit}
height={40}
- fontSize={12}
+ fontSize={SIZE.md}
style={{marginLeft: 10}}
/>
)}
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js b/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js
index 9eff6b6be..e408904ea 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js
@@ -1,22 +1,36 @@
import React, {useEffect, useState} from 'react';
-import {Touchable} from 'react-native';
import {ScrollView, View} from 'react-native';
import {TouchableOpacity} from 'react-native-gesture-handler';
-import Paragraph from '../../../../components/Typography/Paragraph';
+import Animated, {Easing, timing} from 'react-native-reanimated';
import {useTracked} from '../../../../provider';
import {DDS} from '../../../../services/DeviceDetection';
import {
+ eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
- eSendEvent,
} from '../../../../services/EventManager';
-import {dWidth, editing, getElevation} from '../../../../utils';
+import {editing, getElevation} from '../../../../utils';
+import {sleep} from '../../../../utils/TimeUtils';
import ColorGroup from './colorgroup';
import {execCommands} from './commands';
import {formatSelection, properties} from './constants';
import ToolbarItem from './item';
import ToolbarLinkInput from './linkinput';
+let translateValue = new Animated.Value(400);
+let animating = false;
+function animate(val, time = 200) {
+ if (animating) return;
+ timing(translateValue, {
+ toValue: val,
+ duration: time,
+ easing: Easing.in(Easing.ease),
+ }).start(async () => {
+ await sleep(time);
+ animating = false;
+ });
+}
+
const Tooltip = () => {
const [state] = useTracked();
const {colors} = state;
@@ -26,8 +40,8 @@ const Tooltip = () => {
default: null,
type: null,
});
- const [visible, setVisible] = useState(false);
- const floating = group.type === 'table' || DDS.isTab;
+ const floating = group?.type === 'table' || DDS.isTab;
+
useEffect(() => {
eSubscribeEvent('showTooltip', show);
return () => {
@@ -35,187 +49,204 @@ const Tooltip = () => {
};
}, []);
- const show = (data) => {
+ const show = async (data) => {
properties.userBlur = true;
- if (!data) {
- setVisible(false);
+ if (!data && editing.tooltip) {
editing.tooltip = null;
+ animate(70, 100);
+ await sleep(100);
+ setGroup(null);
return;
}
- setGroup(data);
+ if (!data) return;
- setVisible(true);
+ let time = editing.tooltip === 'table' || data.type === 'table' ? 400 : 100;
+ if (data && editing.tooltip) {
+ let translate =
+ editing.tooltip === 'table' || data.type === 'table' ? 400 : 70;
+ animate(translate, time);
+ await sleep(time);
+ }
+ editing.tooltip = data.title;
+ setGroup(data);
+ await sleep(5);
+ animate(0, time);
};
- let ParentElement = (props) =>
- group.type === 'link' || group.type === 'table' || group.title === 'ul' || group.title === "align" ? (
- <View
- style={{
- borderRadius: floating ? 5 : 0,
- padding: floating ? 5 : 0,
- position: 'absolute',
- bottom: floating ? 60 : 50,
- width:
- group.type === 'table' ? 35 * 5 + 15 : floating ? '50%' : '100%',
-
- minHeight: 50,
- backgroundColor: colors.bg,
- alignSelf: 'center',
- flexDirection: 'row',
- borderWidth: floating ? 1 : 0,
- borderColor: floating && colors.nav,
- borderTopWidth: 1,
- borderTopColor: colors.nav,
- justifyContent: 'space-around',
- alignItems: 'center',
- flexDirection: 'row',
+ let style = React.useMemo(() => {
+ return {
+ borderRadius: 5,
+ padding: floating ? 5 : 0,
+ position: 'absolute',
+ bottom: 50,
+ width: group?.type === 'table' ? 35 * 5 + 15 : floating ? '50%' : '100%',
+ minHeight: 50,
+ backgroundColor: colors.nav,
+ alignSelf: 'center',
+ flexDirection: 'row',
+ borderWidth: floating ? 1 : 0,
+ borderColor: floating && colors.nav,
+ zIndex: 10,
+ marginBottom: 0,
+ paddingHorizontal: 6,
+ transform: [
+ {
+ translateY: translateValue,
+ },
+ ],
+ };
+ }, [floating, colors.accent, colors.bg, group?.type]);
- ...getElevation(floating ? 5 : 0),
- zIndex: 999,
- }}
- children={props.children}
- />
- ) : (
- <ScrollView
- style={{
- borderRadius: floating ? 5 : 0,
- position: 'absolute',
- bottom: floating ? 60 : 50,
- width:
- group.type === 'table' ? 35 * 5 + 10 : floating ? '50%' : '100%',
- minHeight: 50,
- backgroundColor: colors.bg,
- alignSelf: 'center',
- flexDirection: 'row',
- borderWidth: floating ? 1 : 0,
- borderColor: floating && colors.nav,
- borderTopWidth: 1,
- borderTopColor: colors.nav,
+ let ParentElement = (props) => (
+ <Animated.View style={style}>
+ {group && /^(link|table|ul|align)$/.test(group.type) ? (
+ <View
+ style={{
+ justifyContent: 'space-around',
+ alignItems: 'center',
+ flexDirection: 'row',
+ width: '100%',
+ backgroundColor: colors.bg,
+ marginVertical: 5,
+ borderRadius: 5,
+ }}
+ children={props.children}></View>
+ ) : (
+ <ScrollView
+ style={{
+ width: '100%',
+ backgroundColor: colors.bg,
+ marginVertical: 5,
+ borderRadius: 5,
+ paddingHorizontal: 0,
+ }}
+ horizontal
+ showsHorizontalScrollIndicator={false}
+ bounces={false}
+ keyboardDismissMode="none"
+ keyboardShouldPersistTaps="always"
+ contentContainerStyle={{
+ justifyContent: 'space-around',
+ alignItems: 'center',
+ flexDirection: 'row',
+ minWidth: '100%',
+ }}
+ children={props.children}
+ />
+ )}
+ </Animated.View>
+ );
- ...getElevation(floating ? 5 : 0),
- zIndex: 999,
- }}
- horizontal
- showsHorizontalScrollIndicator={false}
- bounces={false}
- keyboardDismissMode="none"
- keyboardShouldPersistTaps="always"
- contentContainerStyle={{
- justifyContent: 'space-around',
- alignItems: 'center',
- flexDirection: 'row',
- minWidth: '100%',
- }}
- children={props.children}
- />
- );
return (
- visible && (
- <ParentElement>
- {!group.data && /^(link|video|)$/.test(group.type) && (
- <ToolbarLinkInput
- format={group.type}
- setVisible={setVisible}
- type={group.type}
- value={group.value}
- />
- )}
+ <ParentElement>
+ {group && !group.data && /^(link|video|)$/.test(group.type) && (
+ <ToolbarLinkInput
+ format={group.type}
+ setVisible={() => {
+ show();
+ }}
+ type={group.type}
+ value={group.value}
+ />
+ )}
- {!group.data && group.type === 'table' && (
- <View
- style={{
- width: '100%',
- flexDirection: 'row',
- flexWrap: 'wrap',
- }}>
- {[
- 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,
- ].map((item, index) => (
- <TouchableOpacity
- key={item.toString()}
- onPress={() => {
- let columnCount = 5;
- let rowNumber = Math.floor(index / columnCount);
- let columnNumber = index - rowNumber * columnCount;
- formatSelection(
- execCommands.table(rowNumber + 1, columnNumber + 1),
- );
- eSendEvent('showTooltip');
- }}
- style={{
- width: 25,
- height: 25,
- borderWidth: 1,
- borderColor: colors.icon,
- marginHorizontal: 5,
- marginVertical: 5,
- }}
- />
- ))}
- </View>
- )}
+ {!group?.data && group?.type === 'table' && (
+ <View
+ style={{
+ width: '100%',
+ flexDirection: 'row',
+ flexWrap: 'wrap',
+ }}>
+ {[
+ 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,
+ ].map((item, index) => (
+ <TouchableOpacity
+ key={item.toString()}
+ onPress={() => {
+ let columnCount = 5;
+ let rowNumber = Math.floor(index / columnCount);
+ let columnNumber = index - rowNumber * columnCount;
+ formatSelection(
+ execCommands.table(rowNumber + 1, columnNumber + 1),
+ );
+ eSendEvent('showTooltip');
+ }}
+ style={{
+ width: 25,
+ height: 25,
+ borderWidth: 1,
+ borderColor: colors.icon,
+ marginHorizontal: 5,
+ marginVertical: 5,
+ }}
+ />
+ ))}
+ </View>
+ )}
- {/^(hilitecolor|forecolor|)$/.test(group.type) ? (
- <ColorGroup group={group} />
- ) : null}
+ {/^(hilitecolor|forecolor|)$/.test(group?.type) ? (
+ <ColorGroup group={group} />
+ ) : null}
- {group.data &&
- /^(hilitecolor|forecolor|)$/.test(group.type) === false &&
- group.data.map((item) =>
- group.type === 'link' || group.type === 'video' ? (
- <ToolbarLinkInput
- key={item.formatValue || item.format}
- setVisible={setVisible}
- format={item.format}
- type={item.type}
- showTitle={true}
- premium={item.premium}
- groupFormat={group.title}
- groupDefault={group.default}
- formatValue={item.formatValue}
- fullname={item.fullname}
- />
- ) : (
- <ToolbarItem
- key={item.formatValue || item.format}
- format={item.format}
- formatValue={item.formatValue}
- type={item.type}
- showTitle={item.showTitle}
- premium={item.premium}
- groupFormat={group.title}
- groupDefault={group.default}
- text={item.text}
- fullname={item.fullname}
- />
- ),
- )}
- </ParentElement>
- )
+ {group &&
+ group.data &&
+ /^(hilitecolor|forecolor|)$/.test(group.type) === false &&
+ group.data.map((item) =>
+ /^(video|link|)$/.test(group.type) ? (
+ <ToolbarLinkInput
+ key={item.formatValue || item.format}
+ setVisible={() => {
+ show();
+ }}
+ format={item.format}
+ type={item.type}
+ showTitle={true}
+ premium={item.premium}
+ groupFormat={group.title}
+ groupDefault={group.default}
+ formatValue={item.formatValue}
+ fullname={item.fullname}
+ />
+ ) : (
+ <ToolbarItem
+ key={item.formatValue || item.format}
+ format={item.format}
+ formatValue={item.formatValue}
+ type={item.type}
+ showTitle={item.showTitle}
+ premium={item.premium}
+ groupFormat={group.title}
+ groupDefault={group.default}
+ text={item.text}
+ fullname={item.fullname}
+ />
+ ),
+ )}
+ </ParentElement>
);
};