2020-09-09 11:10:35 +05:00
|
|
|
import React, {createRef, useEffect, useState} from 'react';
|
2020-11-29 12:21:36 +05:00
|
|
|
import {Modal, SafeAreaView, TouchableOpacity, View} from 'react-native';
|
2020-09-09 11:10:35 +05:00
|
|
|
import Animated, {Easing} from 'react-native-reanimated';
|
2020-11-29 12:21:36 +05:00
|
|
|
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
2020-03-26 15:42:37 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-03-26 13:39:04 +05:00
|
|
|
import WebView from 'react-native-webview';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {useTracked} from '../../provider';
|
2020-10-13 17:02:14 +05:00
|
|
|
import {Actions} from '../../provider/Actions';
|
2020-11-29 12:21:36 +05:00
|
|
|
import {DDS} from '../../services/DeviceDetection';
|
2020-03-26 15:50:10 +05:00
|
|
|
import {
|
2020-09-09 11:10:35 +05:00
|
|
|
eSendEvent,
|
2020-03-26 15:50:10 +05:00
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
2020-12-27 14:11:32 +05:00
|
|
|
sendNoteEditedEvent,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../services/EventManager';
|
2020-11-30 16:16:03 +05:00
|
|
|
import {dHeight} from '../../utils';
|
2020-11-29 12:21:36 +05:00
|
|
|
import {db} from '../../utils/DB';
|
2020-03-26 15:50:10 +05:00
|
|
|
import {
|
|
|
|
|
eApplyChanges,
|
|
|
|
|
eShowMergeDialog,
|
|
|
|
|
refreshNotesPage,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../utils/Events';
|
2020-11-30 16:16:03 +05:00
|
|
|
import {normalize, SIZE} from '../../utils/SizeUtils';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {Button} from '../Button';
|
2020-11-29 13:23:46 +05:00
|
|
|
import BaseDialog from '../Dialog/base-dialog';
|
|
|
|
|
import DialogButtons from '../Dialog/dialog-buttons';
|
|
|
|
|
import DialogContainer from '../Dialog/dialog-container';
|
|
|
|
|
import DialogHeader from '../Dialog/dialog-header';
|
|
|
|
|
import {updateEvent} from '../DialogManager/recievers';
|
2020-11-20 01:23:05 +05:00
|
|
|
import Paragraph from '../Typography/Paragraph';
|
2021-01-03 12:40:59 +05:00
|
|
|
import KeepAwake from '@sayem314/react-native-keep-awake';
|
2021-01-05 10:20:16 +05:00
|
|
|
import {timeConverter} from '../../utils/TimeUtils';
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
const {Value, timing} = Animated;
|
2020-04-11 11:11:42 +05:00
|
|
|
|
2020-10-13 17:02:14 +05:00
|
|
|
const firstWebViewHeight = new Value(dHeight * 0.5 - 50);
|
|
|
|
|
const secondWebViewHeight = new Value(dHeight * 0.5 - 50);
|
2020-03-26 13:39:04 +05:00
|
|
|
const primaryWebView = createRef();
|
|
|
|
|
const secondaryWebView = createRef();
|
2020-03-26 15:42:37 +05:00
|
|
|
let note = null;
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-03-26 15:42:37 +05:00
|
|
|
function openEditorAnimation(
|
2020-03-26 13:39:04 +05:00
|
|
|
heightToAnimate,
|
|
|
|
|
extendedHeight = null,
|
|
|
|
|
siblingStatus,
|
2020-11-29 12:35:55 +05:00
|
|
|
insets,
|
2020-03-26 13:39:04 +05:00
|
|
|
) {
|
|
|
|
|
let openConfig = {
|
|
|
|
|
duration: 300,
|
2020-11-29 12:21:36 +05:00
|
|
|
toValue: !siblingStatus
|
2020-11-29 12:35:55 +05:00
|
|
|
? dHeight - (100 + insets.top)
|
|
|
|
|
: dHeight * 0.5 - (50 + insets.top / 2),
|
2020-03-26 13:39:04 +05:00
|
|
|
easing: Easing.inOut(Easing.ease),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let extendConfig = {
|
|
|
|
|
duration: 300,
|
2020-11-29 12:35:55 +05:00
|
|
|
toValue: dHeight * 0.5 - (50 + insets.top / 2),
|
2020-03-26 13:39:04 +05:00
|
|
|
easing: Easing.inOut(Easing.ease),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (extendedHeight) {
|
|
|
|
|
timing(extendedHeight, extendConfig).start();
|
|
|
|
|
}
|
|
|
|
|
timing(heightToAnimate, openConfig).start();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-29 12:35:55 +05:00
|
|
|
function closeEditorAnimation(heightToAnimate, heightToExtend = null, insets) {
|
2020-03-26 13:39:04 +05:00
|
|
|
let closeConfig = {
|
|
|
|
|
duration: 300,
|
|
|
|
|
toValue: 0,
|
|
|
|
|
easing: Easing.inOut(Easing.ease),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let extendConfig = {
|
|
|
|
|
duration: 300,
|
2020-11-29 12:35:55 +05:00
|
|
|
toValue: dHeight - (100 + insets.top),
|
2020-03-26 13:39:04 +05:00
|
|
|
easing: Easing.inOut(Easing.ease),
|
|
|
|
|
};
|
|
|
|
|
if (heightToExtend) {
|
|
|
|
|
timing(heightToExtend, extendConfig).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timing(heightToAnimate, closeConfig).start();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-29 12:21:36 +05:00
|
|
|
let primaryData = null;
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-11-29 12:21:36 +05:00
|
|
|
let secondaryData = null;
|
2020-03-26 13:39:04 +05:00
|
|
|
const MergeEditor = () => {
|
|
|
|
|
const [state, dispatch] = useTracked();
|
2020-09-09 11:10:35 +05:00
|
|
|
const {colors} = state;
|
2020-03-26 15:42:37 +05:00
|
|
|
const [visible, setVisible] = useState(false);
|
2020-03-26 13:39:04 +05:00
|
|
|
const [primary, setPrimary] = useState(true);
|
|
|
|
|
const [secondary, setSecondary] = useState(true);
|
|
|
|
|
const [keepContentFrom, setKeepContentFrom] = useState(null);
|
|
|
|
|
const [copyToSave, setCopyToSave] = useState(null);
|
|
|
|
|
const [disardedContent, setDiscardedContent] = useState(null);
|
2020-11-29 13:23:46 +05:00
|
|
|
const [dialogVisible, setDialogVisible] = useState(false);
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-11-29 12:21:36 +05:00
|
|
|
const insets = useSafeAreaInsets();
|
2020-09-09 11:10:35 +05:00
|
|
|
const postMessageToPrimaryWebView = (message) =>
|
2020-03-26 13:39:04 +05:00
|
|
|
primaryWebView.current?.postMessage(JSON.stringify(message));
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
const postMessageToSecondaryWebView = (message) =>
|
2020-03-26 13:39:04 +05:00
|
|
|
secondaryWebView.current?.postMessage(JSON.stringify(message));
|
|
|
|
|
|
|
|
|
|
const onPrimaryWebViewLoad = () => {
|
|
|
|
|
postMessageToPrimaryWebView({
|
2020-03-26 15:42:37 +05:00
|
|
|
type: 'delta',
|
2020-11-29 12:21:36 +05:00
|
|
|
value: primaryData.data,
|
2020-03-26 13:39:04 +05:00
|
|
|
});
|
2020-09-09 11:10:35 +05:00
|
|
|
let c = {...colors};
|
2020-03-26 13:39:04 +05:00
|
|
|
c.factor = normalize(1);
|
|
|
|
|
postMessageToPrimaryWebView({
|
|
|
|
|
type: 'theme',
|
|
|
|
|
value: c,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSecondaryWebViewLoad = () => {
|
|
|
|
|
postMessageToSecondaryWebView({
|
2020-03-26 15:42:37 +05:00
|
|
|
type: 'delta',
|
2020-11-29 12:21:36 +05:00
|
|
|
value: secondaryData.data,
|
2020-03-26 13:39:04 +05:00
|
|
|
});
|
2020-09-09 11:10:35 +05:00
|
|
|
let c = {...colors};
|
2020-03-26 13:39:04 +05:00
|
|
|
c.factor = normalize(1);
|
|
|
|
|
postMessageToSecondaryWebView({
|
|
|
|
|
type: 'theme',
|
|
|
|
|
value: c,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
const _onShouldStartLoadWithRequest = (request) => {
|
2020-03-26 13:39:04 +05:00
|
|
|
if (request.url.includes('https')) {
|
|
|
|
|
Linking.openURL(request.url);
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
const onMessageFromPrimaryWebView = (evt) => {
|
2020-03-26 15:42:37 +05:00
|
|
|
if (evt.nativeEvent.data !== '') {
|
2020-03-26 13:39:04 +05:00
|
|
|
let data = JSON.parse(evt.nativeEvent.data);
|
2021-01-13 16:32:35 +05:00
|
|
|
|
2020-11-29 12:21:36 +05:00
|
|
|
if (data.type === 'delta') {
|
|
|
|
|
primaryData = data.data;
|
|
|
|
|
}
|
2020-03-26 13:39:04 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
const onMessageFromSecondaryWebView = (evt) => {
|
2020-11-29 12:21:36 +05:00
|
|
|
if (evt.nativeEvent.data === '') {
|
2020-03-26 13:39:04 +05:00
|
|
|
let data = JSON.parse(evt.nativeEvent.data);
|
2020-11-29 12:21:36 +05:00
|
|
|
if (data.type === 'delta') {
|
|
|
|
|
secondaryData = data.data;
|
|
|
|
|
}
|
2020-03-26 13:39:04 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-26 15:42:37 +05:00
|
|
|
const applyChanges = async () => {
|
|
|
|
|
if (keepContentFrom === 'primary') {
|
|
|
|
|
await db.notes.add({
|
|
|
|
|
content: {
|
2020-11-29 12:21:36 +05:00
|
|
|
data: primaryData.data,
|
|
|
|
|
resolved: true,
|
|
|
|
|
type: primaryData.type,
|
2020-03-26 15:42:37 +05:00
|
|
|
},
|
|
|
|
|
id: note.id,
|
2020-03-31 10:55:19 +05:00
|
|
|
conflicted: false,
|
2020-03-26 15:42:37 +05:00
|
|
|
});
|
2020-03-26 15:50:10 +05:00
|
|
|
} else if (keepContentFrom === 'secondary') {
|
2020-03-26 15:42:37 +05:00
|
|
|
await db.notes.add({
|
|
|
|
|
content: {
|
2020-11-29 12:21:36 +05:00
|
|
|
data: primaryData.data,
|
|
|
|
|
type: primaryData.type,
|
|
|
|
|
resolved: true,
|
2020-03-26 15:42:37 +05:00
|
|
|
},
|
|
|
|
|
id: note.id,
|
2020-03-31 10:55:19 +05:00
|
|
|
conflicted: false,
|
2020-03-26 15:42:37 +05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (copyToSave === 'primary') {
|
|
|
|
|
await db.notes.add({
|
|
|
|
|
content: {
|
2020-11-29 12:21:36 +05:00
|
|
|
data: primaryData.data,
|
|
|
|
|
type: primaryData.type,
|
2020-03-26 15:42:37 +05:00
|
|
|
},
|
|
|
|
|
id: null,
|
|
|
|
|
});
|
2020-03-26 15:50:10 +05:00
|
|
|
} else if (copyToSave === 'secondary') {
|
2020-03-26 15:42:37 +05:00
|
|
|
await db.notes.add({
|
|
|
|
|
content: {
|
2020-11-29 12:21:36 +05:00
|
|
|
data: secondaryData.data,
|
|
|
|
|
type: secondaryData.type,
|
2020-03-26 15:42:37 +05:00
|
|
|
},
|
|
|
|
|
id: null,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-26 15:50:10 +05:00
|
|
|
eSendEvent(refreshNotesPage);
|
2021-01-01 18:55:26 +05:00
|
|
|
sendNoteEditedEvent({
|
|
|
|
|
id: note.id,
|
|
|
|
|
forced: true,
|
|
|
|
|
});
|
2020-10-13 17:02:14 +05:00
|
|
|
updateEvent({type: Actions.NOTES});
|
|
|
|
|
updateEvent({type: Actions.FAVORITES});
|
2020-03-26 15:42:37 +05:00
|
|
|
close();
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
const show = async (item) => {
|
2020-03-26 15:42:37 +05:00
|
|
|
note = item;
|
2020-11-29 13:23:46 +05:00
|
|
|
let noteData = await db.content.raw(note.contentId);
|
2020-12-08 14:39:03 +05:00
|
|
|
|
2020-11-29 13:23:46 +05:00
|
|
|
switch (noteData.type) {
|
2020-11-29 12:21:36 +05:00
|
|
|
case 'delta':
|
2020-11-29 13:23:46 +05:00
|
|
|
primaryData = noteData;
|
2020-12-08 14:39:03 +05:00
|
|
|
secondaryData = noteData.conflicted;
|
2020-11-29 12:21:36 +05:00
|
|
|
}
|
2020-04-11 11:11:42 +05:00
|
|
|
setVisible(true);
|
2020-11-29 13:23:46 +05:00
|
|
|
firstWebViewHeight.setValue(dHeight / 2 - (50 + insets.top / 2));
|
|
|
|
|
secondWebViewHeight.setValue(dHeight / 2 - (50 + insets.top / 2));
|
2020-11-29 12:35:55 +05:00
|
|
|
openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true, insets);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eApplyChanges, applyChanges);
|
2020-03-26 15:42:37 +05:00
|
|
|
eSubscribeEvent(eShowMergeDialog, show);
|
2020-03-26 13:39:04 +05:00
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eApplyChanges, applyChanges);
|
2020-03-26 15:42:37 +05:00
|
|
|
eUnSubscribeEvent(eShowMergeDialog, show);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
2020-09-09 11:10:35 +05:00
|
|
|
}, []);
|
2020-03-26 13:39:04 +05:00
|
|
|
|
|
|
|
|
const onPressKeepFromPrimaryWebView = () => {
|
|
|
|
|
if (keepContentFrom == 'primary') {
|
|
|
|
|
setKeepContentFrom(null);
|
2020-11-29 12:35:55 +05:00
|
|
|
openEditorAnimation(
|
|
|
|
|
firstWebViewHeight,
|
|
|
|
|
secondWebViewHeight,
|
|
|
|
|
false,
|
|
|
|
|
insets,
|
|
|
|
|
);
|
2020-03-26 13:39:04 +05:00
|
|
|
} else {
|
|
|
|
|
setKeepContentFrom('primary');
|
2020-11-29 12:35:55 +05:00
|
|
|
closeEditorAnimation(firstWebViewHeight, secondWebViewHeight, insets);
|
2020-03-26 13:39:04 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressSaveCopyFromPrimaryWebView = () => {
|
|
|
|
|
setCopyToSave('primary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressKeepFromSecondaryWebView = () => {
|
|
|
|
|
if (keepContentFrom == 'secondary') {
|
|
|
|
|
setKeepContentFrom(null);
|
2020-11-29 12:35:55 +05:00
|
|
|
openEditorAnimation(
|
|
|
|
|
secondWebViewHeight,
|
|
|
|
|
firstWebViewHeight,
|
|
|
|
|
false,
|
|
|
|
|
insets,
|
|
|
|
|
);
|
2020-03-26 13:39:04 +05:00
|
|
|
} else {
|
|
|
|
|
setKeepContentFrom('secondary');
|
2020-11-29 12:35:55 +05:00
|
|
|
closeEditorAnimation(secondWebViewHeight, firstWebViewHeight, insets);
|
2020-03-26 13:39:04 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressSaveCopyFromSecondaryWebView = () => {
|
|
|
|
|
setCopyToSave('secondary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressDiscardFromPrimaryWebView = () => {
|
|
|
|
|
setDiscardedContent('primary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressDiscardFromSecondaryWebView = () => {
|
|
|
|
|
setDiscardedContent('secondary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
2020-03-26 15:42:37 +05:00
|
|
|
const close = () => {
|
|
|
|
|
setVisible(false);
|
|
|
|
|
setPrimary(true);
|
|
|
|
|
setSecondary(true);
|
|
|
|
|
setCopyToSave(null);
|
|
|
|
|
setDiscardedContent(null);
|
|
|
|
|
setKeepContentFrom(null);
|
2020-12-27 13:51:09 +05:00
|
|
|
setDialogVisible(false);
|
2020-11-29 12:21:36 +05:00
|
|
|
primaryData = null;
|
|
|
|
|
secondaryData = null;
|
2020-03-26 15:42:37 +05:00
|
|
|
primaryText = null;
|
|
|
|
|
secondaryText = null;
|
|
|
|
|
note = null;
|
2020-11-29 12:35:55 +05:00
|
|
|
openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true, insets);
|
2020-03-26 15:42:37 +05:00
|
|
|
};
|
|
|
|
|
|
2020-03-26 13:39:04 +05:00
|
|
|
const params = 'platform=' + Platform.OS;
|
|
|
|
|
const sourceUri =
|
|
|
|
|
(Platform.OS === 'android' ? 'file:///android_asset/' : '') +
|
|
|
|
|
'Web.bundle/loader.html';
|
|
|
|
|
const injectedJS = `if (!window.location.search) {
|
|
|
|
|
var link = document.getElementById('progress-bar');
|
2020-09-09 11:10:35 +05:00
|
|
|
link.href = './site/plaineditor.html?${params}';
|
2020-03-26 13:39:04 +05:00
|
|
|
link.click();
|
|
|
|
|
}`;
|
|
|
|
|
|
2020-11-23 12:32:33 +05:00
|
|
|
return !visible ? null : (
|
2020-11-29 12:21:36 +05:00
|
|
|
<Modal
|
|
|
|
|
statusBarTranslucent
|
|
|
|
|
transparent={false}
|
|
|
|
|
animationType="slide"
|
|
|
|
|
visible={true}>
|
2020-09-09 11:10:35 +05:00
|
|
|
<SafeAreaView
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
backgroundColor: colors.nav,
|
2020-11-29 12:21:36 +05:00
|
|
|
paddingTop: insets.top,
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2021-01-03 12:40:59 +05:00
|
|
|
<KeepAwake />
|
2020-11-29 13:23:46 +05:00
|
|
|
{dialogVisible && (
|
|
|
|
|
<BaseDialog visible={true}>
|
|
|
|
|
<DialogContainer>
|
|
|
|
|
<DialogHeader
|
|
|
|
|
title="Apply Changes"
|
|
|
|
|
paragraph="Apply selected changes to note?"
|
|
|
|
|
/>
|
|
|
|
|
<DialogButtons
|
|
|
|
|
positiveTitle="Apply"
|
|
|
|
|
negativeTitle="Cancel"
|
|
|
|
|
onPressNegative={() => setDialogVisible(false)}
|
|
|
|
|
onPressPositive={applyChanges}
|
|
|
|
|
/>
|
|
|
|
|
</DialogContainer>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
)}
|
|
|
|
|
|
2020-03-26 13:39:04 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
height: '100%',
|
2020-03-26 13:39:04 +05:00
|
|
|
width: '100%',
|
2020-11-29 12:21:36 +05:00
|
|
|
backgroundColor: DDS.isLargeTablet() ? 'rgba(0,0,0,0.3)' : null,
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
backgroundColor: colors.nav,
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: 50,
|
2020-03-26 13:39:04 +05:00
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
2020-09-09 11:10:35 +05:00
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingHorizontal: 12,
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'space-between',
|
2021-01-13 16:32:35 +05:00
|
|
|
maxWidth: '50%',
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
|
|
|
|
<Icon
|
|
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
textAlign: 'center',
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
marginLeft: -8,
|
|
|
|
|
paddingRight: 10,
|
|
|
|
|
paddingVertical: 10,
|
|
|
|
|
}}
|
|
|
|
|
onPress={close}
|
|
|
|
|
size={SIZE.xxl}
|
2020-11-29 12:21:36 +05:00
|
|
|
name="arrow-left"
|
2020-09-09 11:10:35 +05:00
|
|
|
/>
|
2020-03-26 13:39:04 +05:00
|
|
|
<TouchableOpacity
|
2020-09-09 11:10:35 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
if (keepContentFrom === 'primary') return;
|
|
|
|
|
if (!primary) {
|
|
|
|
|
openEditorAnimation(
|
|
|
|
|
firstWebViewHeight,
|
|
|
|
|
secondary && keepContentFrom !== 'secondary'
|
|
|
|
|
? secondWebViewHeight
|
|
|
|
|
: null,
|
|
|
|
|
secondary && keepContentFrom !== 'secondary',
|
2020-11-29 12:35:55 +05:00
|
|
|
insets,
|
2020-09-09 11:10:35 +05:00
|
|
|
);
|
|
|
|
|
setPrimary(true);
|
|
|
|
|
} else {
|
|
|
|
|
closeEditorAnimation(
|
|
|
|
|
firstWebViewHeight,
|
|
|
|
|
secondary && keepContentFrom !== 'secondary'
|
|
|
|
|
? secondWebViewHeight
|
|
|
|
|
: null,
|
2020-11-29 12:35:55 +05:00
|
|
|
insets,
|
2020-09-09 11:10:35 +05:00
|
|
|
);
|
|
|
|
|
setPrimary(false);
|
|
|
|
|
}
|
|
|
|
|
}}
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
flexDirection: 'row',
|
2020-03-26 13:39:04 +05:00
|
|
|
alignItems: 'center',
|
2020-09-09 11:10:35 +05:00
|
|
|
justifyContent: 'space-between',
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2021-01-13 16:32:35 +05:00
|
|
|
<Paragraph
|
|
|
|
|
style={{maxWidth: '80%'}}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
size={SIZE.xs}>
|
2020-12-27 14:11:32 +05:00
|
|
|
Saved on {timeConverter(primaryData.dateEdited)}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Paragraph>
|
2020-09-09 11:10:35 +05:00
|
|
|
<Icon
|
|
|
|
|
size={SIZE.lg}
|
|
|
|
|
name={primary ? 'chevron-up' : 'chevron-down'}
|
|
|
|
|
/>
|
2020-03-26 13:39:04 +05:00
|
|
|
</TouchableOpacity>
|
2020-09-09 11:10:35 +05:00
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
|
}}>
|
|
|
|
|
{keepContentFrom === 'secondary' ? (
|
|
|
|
|
<Button
|
|
|
|
|
width={null}
|
|
|
|
|
onPress={onPressSaveCopyFromPrimaryWebView}
|
|
|
|
|
title="Save Copy"
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
<View style={{width: 10}} />
|
|
|
|
|
{keepContentFrom === 'secondary' ? (
|
|
|
|
|
<Button
|
|
|
|
|
width={null}
|
2021-01-05 10:20:16 +05:00
|
|
|
height={40}
|
2020-09-09 11:10:35 +05:00
|
|
|
title="Discard"
|
2021-01-05 10:20:16 +05:00
|
|
|
type="accent"
|
|
|
|
|
accentColor="red"
|
|
|
|
|
accentText="light"
|
2020-09-09 11:10:35 +05:00
|
|
|
color={colors.errorText}
|
|
|
|
|
onPress={onPressDiscardFromPrimaryWebView}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
{keepContentFrom === 'secondary' ? null : (
|
2021-01-13 16:32:35 +05:00
|
|
|
<>
|
|
|
|
|
<View style={{width: 10}} />
|
|
|
|
|
<Button
|
|
|
|
|
width={null}
|
|
|
|
|
height={40}
|
|
|
|
|
title={keepContentFrom === 'primary' ? 'Undo' : 'Keep'}
|
|
|
|
|
onPress={onPressKeepFromPrimaryWebView}
|
|
|
|
|
color={
|
|
|
|
|
keepContentFrom === 'primary'
|
|
|
|
|
? colors.errorText
|
|
|
|
|
: 'accent'
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2020-09-09 11:10:35 +05:00
|
|
|
)}
|
|
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
</View>
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<Animated.View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
height: firstWebViewHeight,
|
|
|
|
|
}}>
|
|
|
|
|
<WebView
|
|
|
|
|
onLoad={onPrimaryWebViewLoad}
|
|
|
|
|
ref={primaryWebView}
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
}}
|
|
|
|
|
injectedJavaScript={Platform.OS === 'ios' ? injectedJS : null}
|
|
|
|
|
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
|
|
|
|
cacheMode="LOAD_DEFAULT"
|
|
|
|
|
domStorageEnabled={true}
|
|
|
|
|
scrollEnabled={false}
|
|
|
|
|
bounces={false}
|
|
|
|
|
allowFileAccess={true}
|
|
|
|
|
scalesPageToFit={true}
|
|
|
|
|
allowingReadAccessToURL={Platform.OS === 'android' ? true : null}
|
|
|
|
|
allowFileAccessFromFileURLs={true}
|
|
|
|
|
allowUniversalAccessFromFileURLs={true}
|
|
|
|
|
originWhitelist={['*']}
|
|
|
|
|
javaScriptEnabled={true}
|
|
|
|
|
cacheEnabled={true}
|
|
|
|
|
onMessage={onMessageFromPrimaryWebView}
|
|
|
|
|
source={
|
|
|
|
|
Platform.OS === 'ios'
|
|
|
|
|
? {uri: sourceUri}
|
|
|
|
|
: {
|
|
|
|
|
uri: 'file:///android_asset/plaineditor.html',
|
|
|
|
|
baseUrl: 'file:///android_asset/',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Animated.View>
|
2020-03-26 13:39:04 +05:00
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
backgroundColor: colors.nav,
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: 50,
|
2020-03-26 13:39:04 +05:00
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
2020-09-09 11:10:35 +05:00
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingHorizontal: 12,
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'space-between',
|
2021-01-13 16:32:35 +05:00
|
|
|
maxWidth: '50%',
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
|
|
|
|
<TouchableOpacity
|
2020-09-09 11:10:35 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
if (keepContentFrom === 'secondary') return;
|
|
|
|
|
if (!secondary) {
|
|
|
|
|
openEditorAnimation(
|
|
|
|
|
secondWebViewHeight,
|
|
|
|
|
primary && keepContentFrom !== 'primary'
|
|
|
|
|
? firstWebViewHeight
|
|
|
|
|
: null,
|
|
|
|
|
primary && keepContentFrom !== 'primary',
|
2020-11-29 12:35:55 +05:00
|
|
|
insets,
|
2020-09-09 11:10:35 +05:00
|
|
|
);
|
|
|
|
|
setSecondary(true);
|
|
|
|
|
} else {
|
|
|
|
|
closeEditorAnimation(
|
|
|
|
|
secondWebViewHeight,
|
|
|
|
|
primary && keepContentFrom !== 'primary'
|
|
|
|
|
? firstWebViewHeight
|
|
|
|
|
: null,
|
2020-11-29 12:35:55 +05:00
|
|
|
insets,
|
2020-09-09 11:10:35 +05:00
|
|
|
);
|
|
|
|
|
setSecondary(false);
|
|
|
|
|
}
|
|
|
|
|
}}
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
flexDirection: 'row',
|
2020-03-26 13:39:04 +05:00
|
|
|
alignItems: 'center',
|
2020-09-09 11:10:35 +05:00
|
|
|
justifyContent: 'space-between',
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2021-01-13 16:32:35 +05:00
|
|
|
<Paragraph
|
|
|
|
|
style={{maxWidth: '80%'}}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
size={SIZE.xs}>
|
2020-12-27 14:11:32 +05:00
|
|
|
Saved on {timeConverter(secondaryData.dateEdited)}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Paragraph>
|
2020-09-09 11:10:35 +05:00
|
|
|
<Icon
|
|
|
|
|
size={SIZE.lg}
|
|
|
|
|
name={secondary ? 'chevron-up' : 'chevron-down'}
|
|
|
|
|
/>
|
2020-03-26 13:39:04 +05:00
|
|
|
</TouchableOpacity>
|
2020-09-09 11:10:35 +05:00
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
|
}}>
|
|
|
|
|
{keepContentFrom === 'primary' ? (
|
|
|
|
|
<Button
|
|
|
|
|
width={null}
|
2021-01-05 10:20:16 +05:00
|
|
|
height={40}
|
2020-09-09 11:10:35 +05:00
|
|
|
onPress={onPressSaveCopyFromSecondaryWebView}
|
|
|
|
|
title="Save Copy"
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
<View style={{width: 10}} />
|
|
|
|
|
{keepContentFrom === 'primary' ? (
|
|
|
|
|
<Button
|
|
|
|
|
width={null}
|
2021-01-05 10:20:16 +05:00
|
|
|
height={40}
|
2020-09-09 11:10:35 +05:00
|
|
|
title="Discard"
|
2021-01-05 10:20:16 +05:00
|
|
|
type="accent"
|
|
|
|
|
accentColor="red"
|
|
|
|
|
accentText="light"
|
2020-09-09 11:10:35 +05:00
|
|
|
onPress={onPressDiscardFromSecondaryWebView}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2021-01-13 16:32:35 +05:00
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
{keepContentFrom === 'primary' ? null : (
|
2021-01-13 16:32:35 +05:00
|
|
|
<>
|
|
|
|
|
<View style={{width: 10}} />
|
|
|
|
|
<Button
|
|
|
|
|
width={null}
|
|
|
|
|
title={keepContentFrom === 'secondary' ? 'Undo' : 'Keep'}
|
|
|
|
|
onPress={onPressKeepFromSecondaryWebView}
|
|
|
|
|
color={
|
|
|
|
|
keepContentFrom === 'secondary'
|
|
|
|
|
? colors.errorText
|
|
|
|
|
: 'accent'
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2020-09-09 11:10:35 +05:00
|
|
|
)}
|
|
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
</View>
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<Animated.View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
height: secondWebViewHeight,
|
|
|
|
|
}}>
|
|
|
|
|
<WebView
|
|
|
|
|
onLoad={onSecondaryWebViewLoad}
|
|
|
|
|
ref={secondaryWebView}
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
}}
|
|
|
|
|
injectedJavaScript={Platform.OS === 'ios' ? injectedJS : null}
|
|
|
|
|
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
|
|
|
|
cacheMode="LOAD_DEFAULT"
|
|
|
|
|
domStorageEnabled={true}
|
|
|
|
|
scrollEnabled={false}
|
|
|
|
|
bounces={false}
|
|
|
|
|
allowFileAccess={true}
|
|
|
|
|
scalesPageToFit={true}
|
|
|
|
|
allowingReadAccessToURL={Platform.OS === 'android' ? true : null}
|
|
|
|
|
allowFileAccessFromFileURLs={true}
|
|
|
|
|
allowUniversalAccessFromFileURLs={true}
|
|
|
|
|
originWhitelist={['*']}
|
|
|
|
|
javaScriptEnabled={true}
|
|
|
|
|
cacheEnabled={true}
|
|
|
|
|
onMessage={onMessageFromSecondaryWebView}
|
|
|
|
|
source={
|
|
|
|
|
Platform.OS === 'ios'
|
|
|
|
|
? {uri: sourceUri}
|
|
|
|
|
: {
|
|
|
|
|
uri: 'file:///android_asset/plaineditor.html',
|
|
|
|
|
baseUrl: 'file:///android_asset/',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Animated.View>
|
|
|
|
|
</View>
|
|
|
|
|
</SafeAreaView>
|
2020-03-26 13:39:04 +05:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MergeEditor;
|