Files
notesnook/apps/mobile/share/index.js

922 lines
24 KiB
JavaScript
Raw Normal View History

import Clipboard from '@react-native-clipboard/clipboard';
2022-01-31 13:36:53 +05:00
import { getLinkPreview } from 'link-preview-js';
import { HTMLRootElement } from 'node-html-parser/dist/nodes/html';
2022-02-01 14:43:44 +05:00
import React, { Fragment, useEffect, useRef, useState } from 'react';
2021-01-08 12:30:20 +05:00
import {
ActivityIndicator,
2021-10-11 14:06:17 +05:00
Alert,
Keyboard,
2021-01-08 12:30:20 +05:00
KeyboardAvoidingView,
2022-02-01 14:43:44 +05:00
Modal,
NativeModules,
2021-01-08 12:30:20 +05:00
Platform,
2021-07-08 09:34:21 +05:00
SafeAreaView,
2022-01-31 13:36:53 +05:00
ScrollView,
2021-10-26 12:28:35 +05:00
StatusBar,
2021-10-11 14:06:17 +05:00
Text,
TouchableOpacity,
2022-02-01 14:43:44 +05:00
UIManager,
2021-07-07 11:13:43 +05:00
useWindowDimensions,
2021-07-30 10:18:14 +05:00
View
2021-01-08 12:30:20 +05:00
} from 'react-native';
2022-02-01 14:43:44 +05:00
import Animated, { acc, Easing, timing, useValue } from 'react-native-reanimated';
2022-01-24 11:51:28 +05:00
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2021-07-07 11:13:43 +05:00
import WebView from 'react-native-webview';
import ShareExtension from 'rn-extensions-share';
2022-01-31 13:36:53 +05:00
import isURL from 'validator/lib/isURL';
2022-01-24 11:51:28 +05:00
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../src/services/EventManager';
import { getElevation } from '../src/utils';
import { db } from '../src/utils/database';
2022-02-28 13:48:59 +05:00
import Storage from '../src/utils/database/storage';
import { sleep } from '../src/utils/time';
2022-01-24 11:51:28 +05:00
import { Search } from './search';
import { useShareStore } from './store';
2021-07-06 15:01:52 +05:00
2021-07-07 11:44:15 +05:00
const AnimatedKAV = Animated.createAnimatedComponent(KeyboardAvoidingView);
2021-07-08 09:34:21 +05:00
const AnimatedSAV = Animated.createAnimatedComponent(SafeAreaView);
2021-07-06 15:01:52 +05:00
async function sanitizeHtml(site) {
try {
let html = await fetch(site);
html = await html.text();
2022-01-31 13:36:53 +05:00
return sanitize(html, site);
2021-07-06 15:01:52 +05:00
} catch (e) {
return '';
}
}
function makeHtmlFromUrl(url) {
2021-07-07 11:13:43 +05:00
return `<a style="overflow-wrap:anywhere;white-space:pre-wrap" href='${url}' target='_blank'>${url}</a>`;
2021-07-06 15:01:52 +05:00
}
function makeHtmlFromPlainText(text) {
2021-07-07 11:13:43 +05:00
if (!text) return '';
2021-12-03 10:00:03 +05:00
2021-12-09 01:02:21 +05:00
return `<p style="overflow-wrap:anywhere;white-space:pre-wrap" >${text.replace(
/(?:\r\n|\r|\n)/g,
'<br>'
)}</p>`;
2021-07-06 15:01:52 +05:00
}
function getBaseUrl(site) {
var url = site.split('/').slice(0, 3).join('/');
return url;
}
2022-01-31 13:36:53 +05:00
/**
*
* @param {HTMLRootElement} document
*/
function wrapTablesWithDiv(document) {
const tables = document.getElementsByTagName('table');
for (let table of tables) {
table.setAttribute('contenteditable', 'true');
const div = document.createElement('div');
div.setAttribute('contenteditable', 'false');
div.innerHTML = table.outerHTML;
div.classList.add('table-container');
table.replaceWith(div);
}
return document;
}
let elementBlacklist = [
'script',
'button',
'input',
'textarea',
'style',
'form',
'link',
'head',
'nav',
'iframe',
'canvas',
'select',
'dialog',
'footer'
];
/**
*
* @param {HTMLRootElement} document
*/
function removeInvalidElements(document) {
let elements = document.querySelectorAll(elementBlacklist.join(','));
for (let element of elements) {
element.remove();
}
return document;
}
/**
*
* @param {HTMLRootElement} document
*/
function replaceSrcWithAbsoluteUrls(document, baseUrl) {
console.log('parsing:', document);
let images = document.querySelectorAll('img');
console.log(images.length);
for (var i = 0; i < images.length; i++) {
let img = images[i];
2022-01-31 13:36:53 +05:00
let url = getBaseUrl(baseUrl);
2022-01-17 19:02:41 +05:00
let src = img.getAttribute('src');
if (src.startsWith('/')) {
if (src.startsWith('//')) {
src = src.replace('//', 'https://');
} else {
2022-01-17 19:02:41 +05:00
src = url + src;
}
}
2022-01-17 19:02:41 +05:00
if (src.startsWith('data:')) {
2022-01-31 13:36:53 +05:00
img.remove();
} else {
img.setAttribute('src', src);
2021-10-09 16:44:44 +05:00
}
}
2022-01-31 13:36:53 +05:00
console.log('end');
return document;
}
/**
*
* @param {HTMLRootElement} document
*/
function fixCodeBlocks(document) {
let elements = document.querySelectorAll('code,pre');
console.log(elements.length);
for (let element of elements) {
element.classList.add('.hljs');
}
return document;
}
function sanitize(html, baseUrl) {
let { parse } = require('node-html-parser');
let parser = parse(html);
parser = wrapTablesWithDiv(parser);
parser = removeInvalidElements(parser);
parser = replaceSrcWithAbsoluteUrls(parser, baseUrl);
parser = fixCodeBlocks(parser);
2022-01-31 14:00:46 +05:00
let htmlString = parser.outerHTML;
htmlString = htmlString + `<hr>${makeHtmlFromUrl(baseUrl)}`;
return htmlString;
}
2021-07-07 08:46:29 +05:00
let defaultNote = {
title: null,
id: null,
content: {
type: 'tiny',
2021-07-30 10:18:14 +05:00
data: null
}
2021-07-07 08:46:29 +05:00
};
2021-10-08 12:22:47 +05:00
const modes = {
1: {
type: 'text',
title: 'Plain text',
icon: 'card-text-outline'
},
2: {
type: 'clip',
title: 'Web clip',
icon: 'web'
},
3: {
type: 'link',
title: 'Link',
icon: 'link'
}
};
2022-01-24 11:51:28 +05:00
const NotesnookShare = ({ quicknote = false }) => {
2021-10-11 11:25:22 +05:00
const colors = useShareStore(state => state.colors);
const accent = useShareStore(state => state.accent);
2021-10-11 11:25:22 +05:00
const appendNote = useShareStore(state => state.appendNote);
2022-01-24 11:51:28 +05:00
const [note, setNote] = useState({ ...defaultNote });
2021-07-06 15:01:52 +05:00
const [loadingIntent, setLoadingIntent] = useState(true);
2021-07-07 08:46:29 +05:00
const [loading, setLoading] = useState(false);
2021-07-06 15:01:52 +05:00
const [floating, setFloating] = useState(false);
const [rawData, setRawData] = useState({
type: null,
2021-07-30 10:18:14 +05:00
value: null
2021-07-06 15:01:52 +05:00
});
2021-10-11 11:25:22 +05:00
const [mode, setMode] = useState(1);
const keyboardHeight = useRef(0);
2022-01-24 11:51:28 +05:00
const { width, height } = useWindowDimensions();
2021-07-07 08:46:29 +05:00
const webviewRef = useRef();
2021-07-07 11:44:15 +05:00
const opacity = useValue(0);
const translate = useValue(1000);
2022-01-24 11:51:28 +05:00
const insets = Platform.OS === 'android' ? { top: StatusBar.currentHeight } : useSafeAreaInsets();
2021-10-08 12:22:47 +05:00
const prevAnimation = useRef(null);
2021-10-11 11:25:22 +05:00
const [showSearch, setShowSearch] = useState(false);
2022-02-01 14:43:44 +05:00
const [kh, setKh] = useState(0);
2021-07-07 11:44:15 +05:00
const animate = (opacityV, translateV) => {
2021-10-08 12:22:47 +05:00
prevAnimation.current = translateV;
2021-07-08 09:34:21 +05:00
if (Platform.OS === 'ios') return;
2021-07-07 11:44:15 +05:00
timing(opacity, {
toValue: opacityV,
duration: 300,
2021-07-30 10:18:14 +05:00
easing: Easing.in(Easing.ease)
2021-07-07 11:44:15 +05:00
}).start();
timing(translate, {
toValue: translateV,
duration: 300,
2021-07-30 10:18:14 +05:00
easing: Easing.in(Easing.ease)
2021-07-07 11:44:15 +05:00
}).start();
};
2021-07-06 15:01:52 +05:00
const onKeyboardDidShow = event => {
2021-10-08 12:22:47 +05:00
let kHeight = event.endCoordinates.height;
2021-10-09 16:44:44 +05:00
keyboardHeight.current = kHeight;
2022-02-01 14:43:44 +05:00
setKh(kHeight);
console.log('keyboard show/hide');
};
2021-10-08 12:22:47 +05:00
const onKeyboardDidHide = () => {
2021-10-09 16:44:44 +05:00
keyboardHeight.current = 0;
2022-02-01 14:43:44 +05:00
setKh(0);
console.log('keyboard hide');
};
2021-10-08 12:22:47 +05:00
2021-07-06 15:01:52 +05:00
useEffect(() => {
useShareStore.getState().setAccent();
let keyboardWillChangeFrame = Keyboard.addListener(
'keyboardWillChangeFrame',
onKeyboardWillChangeFrame
);
2022-01-24 11:51:28 +05:00
let keyboardDidShow = Keyboard.addListener('keyboardDidShow', onKeyboardDidShow);
let keyboardDidHide = Keyboard.addListener('keyboardDidHide', onKeyboardDidHide);
2021-07-06 15:01:52 +05:00
return () => {
2021-10-08 12:22:47 +05:00
keyboardWillChangeFrame?.remove();
keyboardDidShow?.remove();
keyboardDidHide?.remove();
2021-07-06 15:01:52 +05:00
};
}, []);
2021-07-06 15:01:52 +05:00
const onKeyboardWillChangeFrame = event => {
2021-07-08 09:34:21 +05:00
setFloating(event.endCoordinates.width !== width);
2021-07-06 15:01:52 +05:00
};
const showLinkPreview = async (note, link) => {
let _note = note;
_note.content.data = makeHtmlFromUrl(link);
2021-07-06 15:01:52 +05:00
try {
2021-07-07 08:46:29 +05:00
let preview = await getLinkPreview(link);
2022-01-17 19:02:41 +05:00
_note.title = preview.title;
2021-07-07 08:46:29 +05:00
} catch (e) {
console.log(e);
}
return note;
2021-07-06 15:01:52 +05:00
};
const loadData = async () => {
2021-01-08 12:30:20 +05:00
try {
2021-10-09 16:44:44 +05:00
defaultNote.content.data = null;
2022-01-24 11:51:28 +05:00
setNote({ ...defaultNote });
2021-01-08 12:30:20 +05:00
const data = await ShareExtension.data();
2021-10-08 12:22:47 +05:00
if (!data || data.length === 0) {
setRawData({
value: ''
});
setLoadingIntent(false);
return;
}
2022-01-24 11:51:28 +05:00
let note = { ...defaultNote };
for (let item of data) {
2021-07-07 08:46:29 +05:00
if (item.type === 'text') {
setRawData(item);
2022-01-04 11:27:20 +05:00
if (isURL(item.value)) {
note = await showLinkPreview(note, item.value);
2021-07-07 08:46:29 +05:00
} else {
note.content.data = makeHtmlFromPlainText(item.value);
2021-07-07 08:46:29 +05:00
}
}
2021-02-09 16:32:27 +05:00
}
2022-01-24 11:51:28 +05:00
setNote({ ...note });
2021-07-07 08:46:29 +05:00
} catch (e) {}
setLoadingIntent(false);
};
2021-02-09 16:32:27 +05:00
2021-07-07 08:46:29 +05:00
useEffect(() => {
console.log('setting value in storage');
2021-07-07 08:46:29 +05:00
loadData();
2021-10-11 11:25:22 +05:00
useShareStore.getState().restoreAppendNote();
2021-10-08 12:22:47 +05:00
sleep(50).then(() => {
2021-07-07 11:44:15 +05:00
animate(1, 0);
sleep(500).then(r => {
Storage.write('shareExtensionOpened', 'opened');
});
2021-07-07 11:44:15 +05:00
});
2021-07-07 08:46:29 +05:00
}, []);
2021-07-07 11:44:15 +05:00
const close = async () => {
animate(0, 1000);
await sleep(300);
2022-01-24 11:51:28 +05:00
setNote({ ...defaultNote });
2021-07-30 10:18:14 +05:00
setLoadingIntent(true);
2021-10-11 14:06:17 +05:00
if (quicknote) {
ShareExtension.openURL('ShareMedia://MainApp');
} else {
ShareExtension.close();
}
2021-01-08 12:30:20 +05:00
};
2021-07-07 08:46:29 +05:00
const onLoad = () => {
2021-10-09 16:44:44 +05:00
postMessage(webviewRef, 'htmldiff', note.content?.data || '');
2022-01-31 13:36:53 +05:00
console.log('on load');
setTimeout(() => {
2022-01-31 13:36:53 +05:00
let theme = { ...colors };
theme.factor = 1;
webviewRef.current?.injectJavaScript(`
2022-01-31 13:36:53 +05:00
document.querySelector('.htmldiff_div').setAttribute('contenteditable', 'true');`);
2021-12-09 01:02:21 +05:00
2022-01-31 13:36:53 +05:00
webviewRef.current?.injectJavaScript(`(function() {
try {
pageTheme.colors = ${JSON.stringify(theme)};
setTheme();
} catch(e) {
console.log(e);
}
})();
`);
}, 300);
2021-07-07 08:46:29 +05:00
};
function postMessage(webview, type, value = null) {
let message = {
type: type,
2021-07-30 10:18:14 +05:00
value
2021-07-07 08:46:29 +05:00
};
webview.current?.postMessage(JSON.stringify(message));
}
const onPress = async () => {
2022-01-24 11:51:28 +05:00
let content = await getContent();
2022-02-25 15:11:07 +05:00
if (!content || content === '' || typeof content !== 'string') {
return;
}
2021-07-07 08:46:29 +05:00
setLoading(true);
2021-10-11 11:25:22 +05:00
await db.init();
await db.notes.init();
if (appendNote && !db.notes.note(appendNote.id)) {
useShareStore.getState().setAppendNote(null);
Alert.alert('The note you are trying to append to has been deleted.');
return;
}
let _note;
if (appendNote && db.notes.note(appendNote.id)) {
let raw = await db.content.raw(appendNote.contentId);
_note = {
content: {
2021-10-11 11:25:22 +05:00
data: raw.data + '\n' + content,
type: 'tiny'
2021-10-11 11:25:22 +05:00
},
2021-12-25 14:09:01 +05:00
id: appendNote.id,
2022-01-17 19:02:41 +05:00
sessionId: Date.now()
};
2021-01-08 12:30:20 +05:00
} else {
2022-01-24 11:51:28 +05:00
_note = { ...note };
2021-10-11 11:25:22 +05:00
_note.content.data = content;
2021-12-25 14:09:01 +05:00
_note.sessionId = Date.now();
2021-01-08 12:30:20 +05:00
}
2021-10-11 11:25:22 +05:00
await db.notes.add(_note);
2021-01-08 12:30:20 +05:00
await Storage.write('notesAddedFromIntent', 'added');
2021-07-07 11:13:43 +05:00
close();
2021-10-11 11:25:22 +05:00
setLoading(false);
2021-01-08 12:30:20 +05:00
};
2021-10-09 16:44:44 +05:00
const sourceUri = 'Web.bundle/site/plaineditor.html';
2021-07-08 09:34:21 +05:00
const onShouldStartLoadWithRequest = request => {
if (request.url.includes('/site/plaineditor.html')) {
return true;
} else {
return false;
}
};
const getContent = () => {
return new Promise(resolve => {
let oncontent = value => {
eUnSubscribeEvent('share_content_event', oncontent);
resolve(value);
};
eSubscribeEvent('share_content_event', oncontent);
webviewRef.current?.injectJavaScript(`(function() {
let html = document.querySelector(".htmldiff_div").innerHTML;
if (!html) {
html = '';
}
reactNativeEventHandler('tiny', html);
})();`);
});
};
const onMessage = event => {
if (!event) return;
let data = JSON.parse(event.nativeEvent.data);
if (data.type === 'tiny') {
eSendEvent('share_content_event', data.value);
}
};
useEffect(() => {
2022-01-25 19:43:58 +05:00
useShareStore.getState().setColors();
onLoad();
}, [note]);
2021-10-31 10:30:21 +05:00
const changeMode = async m => {
setMode(m);
2021-10-11 11:25:22 +05:00
2021-10-31 10:30:21 +05:00
setLoading(true);
try {
if (m === 2) {
let html = await sanitizeHtml(rawData.value);
setNote(note => {
note.content.data = html;
2022-01-24 11:51:28 +05:00
return { ...note };
2021-10-31 10:30:21 +05:00
});
} else {
2022-01-04 11:27:20 +05:00
let html = isURL(rawData.value)
2021-10-31 10:30:21 +05:00
? makeHtmlFromUrl(rawData.value)
: makeHtmlFromPlainText(rawData.value);
setNote(note => {
note.content.data = html;
2022-01-24 11:51:28 +05:00
return { ...note };
2021-10-31 10:30:21 +05:00
});
}
} catch (e) {
} finally {
setLoading(false);
2021-10-11 11:25:22 +05:00
}
};
const onPaste = async () => {
let text = await Clipboard.getString();
if (text) {
let content = await getContent();
setNote(note => {
note.content.data = content + '\n' + makeHtmlFromPlainText(text);
2022-01-24 11:51:28 +05:00
return { ...note };
2021-10-11 11:25:22 +05:00
});
}
};
2021-10-09 16:44:44 +05:00
2022-02-01 14:43:44 +05:00
const Outer = Platform.OS === 'android' ? Modal : Fragment;
const outerProps =
Platform.OS === 'android'
? {
animationType: 'fade',
transparent: true,
visible: true
}
: {};
2021-07-07 08:46:29 +05:00
return (
2022-02-01 14:43:44 +05:00
<Outer {...outerProps}>
<AnimatedSAV
style={{
width: width > 500 ? 500 : width,
height: height - kh,
opacity: Platform.OS !== 'ios' ? opacity : 1,
alignSelf: 'center',
justifyContent: 'flex-end'
}}
>
{quicknote && !showSearch ? (
<View
style={{
width: '100%',
backgroundColor: colors.bg,
height: 50 + insets.top,
paddingTop: insets.top,
...getElevation(1),
marginTop: -insets.top,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between'
}}
>
<Button
type="action"
icon="close"
iconColor={colors.pri}
onPress={() => {
if (showSearch) {
console.log('hide search');
setShowSearch(false);
animate(1, 0);
} else {
close();
}
}}
style={{
width: 50,
height: 50,
marginBottom: 0
}}
iconSize={25}
/>
<Text
style={{
color: colors.pri,
fontSize: 17,
fontFamily: 'OpenSans-Regular'
}}
>
Quick note
</Text>
<Button
type="action"
icon="check"
iconColor={accent.color}
onPress={onPress}
style={{
width: 50,
height: 50,
marginBottom: 0
}}
iconSize={25}
/>
</View>
) : (
<TouchableOpacity
activeOpacity={1}
onPress={() => {
if (showSearch) {
console.log('hide search');
setShowSearch(false);
animate(1, 0);
} else {
close();
}
}}
style={{
2022-02-01 14:43:44 +05:00
width: '100%',
height: '100%',
position: 'absolute'
2022-01-24 11:51:28 +05:00
}}
>
2022-02-01 14:43:44 +05:00
<View
style={{
width: '100%',
height: '100%',
backgroundColor: 'white',
opacity: 0.01
}}
/>
<View />
</TouchableOpacity>
)}
{showSearch ? (
<Search
quicknote={quicknote}
getKeyboardHeight={() => keyboardHeight.current}
close={() => {
2021-10-11 14:06:17 +05:00
setShowSearch(false);
animate(1, 0);
}}
/>
2022-02-01 14:43:44 +05:00
) : null}
<View
style={{
2022-02-01 14:43:44 +05:00
paddingVertical: 25,
backgroundColor: 'transparent',
marginBottom: insets.top,
display: showSearch ? 'none' : 'flex'
2022-01-24 11:51:28 +05:00
}}
>
2022-02-01 14:43:44 +05:00
<View
2021-10-09 16:44:44 +05:00
style={{
2022-02-01 14:43:44 +05:00
maxHeight: '100%',
paddingHorizontal: 12
2022-01-24 11:51:28 +05:00
}}
>
2022-02-01 14:43:44 +05:00
<ScrollView
horizontal
contentContainerStyle={{
alignItems: 'center',
height: 50
2022-01-25 19:33:25 +05:00
}}
2021-10-09 16:44:44 +05:00
style={{
2022-02-01 14:43:44 +05:00
width: '100%',
height: 50,
borderRadius: 10,
flexDirection: 'row',
bottom: -10
2021-10-09 16:44:44 +05:00
}}
2022-02-01 14:43:44 +05:00
>
<Button
color={colors.nav}
onPress={() => {
useShareStore.getState().setAppendNote(null);
}}
icon="plus"
iconSize={18}
iconColor={!appendNote ? accent.color : colors.icon}
title="New note"
textColor={!appendNote ? accent.color : colors.icon}
type="rounded"
textStyle={{
fontSize: 13
}}
style={{
paddingHorizontal: 12,
...getElevation(1),
height: 35
}}
/>
2021-10-09 16:44:44 +05:00
<Button
2022-02-01 14:43:44 +05:00
color={colors.nav}
onPress={() => {
setShowSearch(true);
animate(1, 1000);
}}
icon="text-short"
iconSize={18}
iconColor={appendNote ? accent.color : colors.icon}
title={`${appendNote ? appendNote.title.slice(0, 25) : 'Append to note'}`}
textColor={appendNote ? accent.color : colors.icon}
type="rounded"
textStyle={{
fontSize: 13
}}
style={{
2022-02-01 14:43:44 +05:00
paddingHorizontal: 12,
...getElevation(1),
height: 35
}}
/>
2022-02-01 14:43:44 +05:00
</ScrollView>
2021-01-08 12:30:20 +05:00
<View
style={{
2022-02-01 14:43:44 +05:00
width: '100%'
2022-01-24 11:51:28 +05:00
}}
>
<View
style={{
2022-02-01 14:43:44 +05:00
marginTop: 10,
minHeight: 100,
borderRadius: 10,
...getElevation(quicknote ? 1 : 5),
backgroundColor: colors.bg,
overflow: 'hidden'
2022-01-24 11:51:28 +05:00
}}
>
2022-02-01 14:43:44 +05:00
<View
2021-10-08 12:22:47 +05:00
style={{
width: '100%',
2022-02-01 14:43:44 +05:00
height: height * 0.3,
paddingBottom: 15,
borderRadius: 10
}}
2022-02-01 14:43:44 +05:00
>
<WebView
onLoad={onLoad}
ref={webviewRef}
style={{
width: '100%',
height: '100%',
borderRadius: 10,
backgroundColor: 'transparent'
}}
cacheMode="LOAD_DEFAULT"
domStorageEnabled={true}
scrollEnabled={true}
bounces={false}
allowFileAccess={true}
scalesPageToFit={true}
allowingReadAccessToURL={Platform.OS === 'android' ? true : null}
onMessage={onMessage}
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
allowFileAccessFromFileURLs={true}
allowUniversalAccessFromFileURLs={true}
originWhitelist={['*']}
javaScriptEnabled={true}
cacheEnabled={true}
source={
Platform.OS === 'ios'
? { uri: sourceUri }
: {
uri: 'file:///android_asset/plaineditor.html',
baseUrl: 'file:///android_asset/'
}
}
/>
</View>
2021-10-08 12:22:47 +05:00
2022-02-01 14:43:44 +05:00
{appendNote ? (
<Text
style={{
fontSize: 12,
color: colors.icon,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: 12,
marginBottom: 10,
flexWrap: 'wrap'
}}
>
Above content will append to{' '}
<Text
style={{
color: accent.color,
fontFamily: 'OpenSans-SemiBold'
}}
>
"{appendNote.title}"
</Text>{' '}
. Click on "New note" to create a new note.
</Text>
) : null}
<View
2021-10-11 11:25:22 +05:00
style={{
2022-02-01 14:43:44 +05:00
flexDirection: 'row',
2021-10-11 11:25:22 +05:00
paddingHorizontal: 12,
2022-02-01 14:43:44 +05:00
alignItems: 'flex-end',
justifyContent: 'space-between',
width: '100%'
2022-01-24 11:51:28 +05:00
}}
>
2022-02-01 14:43:44 +05:00
<View
2021-10-11 11:25:22 +05:00
style={{
2022-02-01 14:43:44 +05:00
flexDirection: 'row'
2022-01-24 11:51:28 +05:00
}}
>
2022-02-01 14:43:44 +05:00
{rawData.value && isURL(rawData.value) ? (
<Button
color={mode == 2 ? colors.shade : colors.nav}
icon={modes[2].icon}
onPress={() => changeMode(2)}
title={modes[2].title}
iconSize={18}
iconColor={mode == 2 ? accent.color : colors.icon}
textColor={mode == 2 ? accent.color : colors.icon}
type="rounded"
style={{ paddingHorizontal: 12 }}
/>
) : null}
<Button
color={mode == 1 ? colors.shade : colors.nav}
icon={modes[1].icon}
onPress={() => changeMode(1)}
title={modes[1].title}
iconSize={18}
iconColor={mode == 1 ? accent.color : colors.icon}
textColor={mode == 1 ? accent.color : colors.icon}
type="rounded"
style={{ paddingHorizontal: 12 }}
/>
</View>
{!quicknote ? (
<Button
color={accent.color}
onPress={onPress}
loading={loading || loadingIntent}
icon="check"
iconSize={20}
iconColor={colors.light}
style={{
paddingHorizontal: 0,
height: 40,
width: 40,
borderRadius: 100,
minWidth: 0
}}
/>
) : null}
</View>
2021-02-09 16:32:27 +05:00
</View>
2021-07-07 08:46:29 +05:00
</View>
2022-02-01 14:43:44 +05:00
<View
style={{
height: Platform.isPad ? 150 : Platform.OS === 'ios' ? 110 : 0
}}
/>
</View>
</View>
2022-02-01 14:43:44 +05:00
</AnimatedSAV>
</Outer>
2021-07-07 08:46:29 +05:00
);
};
2021-10-08 12:22:47 +05:00
const Button = ({
title,
onPress,
color,
loading,
style,
textStyle,
icon,
2021-10-11 14:06:17 +05:00
iconSize = 22,
2021-10-08 12:22:47 +05:00
type = 'button',
2021-10-11 11:25:22 +05:00
iconColor = 'gray',
textColor = 'white',
fontSize = 18
2021-10-08 12:22:47 +05:00
}) => {
const types = {
action: {
2021-10-11 11:25:22 +05:00
style: {
width: 60,
height: 60,
borderRadius: 100,
minWidth: 0,
paddingHorizontal: 0
},
textStyle: {}
2021-10-08 12:22:47 +05:00
},
button: {
2021-10-11 11:25:22 +05:00
style: {
height: 50,
borderRadius: 5,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
marginBottom: 10,
minWidth: 80,
paddingHorizontal: 20
},
textStyle: {}
},
rounded: {
style: {
marginRight: 15,
height: 30,
borderRadius: 100,
paddingHorizontal: 6,
marginTop: -2.5
},
textStyle: {
fontSize: 12,
marginLeft: 5
}
2021-10-08 12:22:47 +05:00
}
};
2021-07-07 08:46:29 +05:00
return (
<TouchableOpacity
onPress={onPress}
activeOpacity={0.8}
style={[
{
backgroundColor: color,
height: 50,
borderRadius: 5,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
marginBottom: 10,
2021-07-08 09:34:21 +05:00
minWidth: 80,
2021-07-30 10:18:14 +05:00
paddingHorizontal: 20
2021-07-07 08:46:29 +05:00
},
2021-10-11 11:25:22 +05:00
types[type].style,
2021-07-30 10:18:14 +05:00
style
2022-01-24 11:51:28 +05:00
]}
>
2021-12-03 09:21:41 +05:00
{loading ? <ActivityIndicator color={iconColor} /> : null}
2021-07-07 08:46:29 +05:00
2022-01-24 11:51:28 +05:00
{icon && !loading ? <Icon name={icon} size={iconSize} color={iconColor || 'white'} /> : null}
2021-10-08 12:22:47 +05:00
2021-12-03 09:21:41 +05:00
{title ? (
2021-10-08 12:22:47 +05:00
<Text
style={[
{
fontSize: fontSize || 18,
fontFamily: 'OpenSans-Regular',
2021-10-11 11:25:22 +05:00
color: textColor,
2021-10-08 12:22:47 +05:00
marginLeft: loading ? 10 : 0
},
2022-01-25 19:33:25 +05:00
types[type].textStyle,
textStyle
2022-01-24 11:51:28 +05:00
]}
>
2021-10-08 12:22:47 +05:00
{title}
</Text>
2021-12-03 09:21:41 +05:00
) : null}
2021-07-07 08:46:29 +05:00
</TouchableOpacity>
);
};
export default NotesnookShare;