From a7fafd79253c22f1bf466c72897a73f1a2019ce4 Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Sun, 19 May 2024 09:59:32 +0800 Subject: [PATCH 1/3] minimum example --- example/src/App.tsx | 189 ++------------------------------------------ 1 file changed, 7 insertions(+), 182 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 473126c6..a16edeff 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,197 +1,22 @@ import * as React from 'react'; -import {Button, Platform, StyleSheet, Text, View} from 'react-native'; - +import {StyleSheet, View} from 'react-native'; import {MarkdownTextInput} from '@expensify/react-native-live-markdown'; -import type {TextInput} from 'react-native'; - -const DEFAULT_TEXT = ['Hello, *world*!', 'https://expensify.com', '# Lorem ipsum', '> Hello world', '`foo`', '```\nbar\n```', '@here', '@someone@swmansion.com', '#room-mention'].join('\n'); - -function isWeb() { - return Platform.OS === 'web'; -} - -function getPlatform() { - if (isWeb()) { - return 'web'; - } - // @ts-expect-error it works - return Platform.constants.systemName || Platform.constants.Brand; -} - -function getPlatformVersion() { - return Platform.Version; -} - -function getBundle() { - return __DEV__ ? 'dev' : 'production'; -} - -function getRuntime() { - if ('HermesInternal' in global) { - const version = - // @ts-expect-error this is fine - // eslint-disable-next-line es/no-optional-chaining - global.HermesInternal?.getRuntimeProperties?.()['OSS Release Version']; - return `Hermes (${version})`; - } - if ('_v8runtime' in global) { - // @ts-expect-error this is fine - // eslint-disable-next-line no-underscore-dangle - const version = global._v8runtime().version; - return `V8 (${version})`; - } - return 'JSC'; -} - -function getArchitecture() { - return 'nativeFabricUIManager' in global ? 'Fabric' : 'Paper'; -} - -function getReactNativeVersion() { - const {major, minor, patch} = Platform.constants.reactNativeVersion; - return `${major}.${minor}.${patch}`; -} - -function getRandomColor() { - return `#${Math.floor(Math.random() * 16777215) - .toString(16) - .padStart(6, '0')}`; -} export default function App() { - const [value, setValue] = React.useState(DEFAULT_TEXT); - const [markdownStyle, setMarkdownStyle] = React.useState({}); - const [selection, setSelection] = React.useState({start: 0, end: 0}); - - // TODO: use MarkdownTextInput ref instead of TextInput ref - const ref = React.useRef(null); - return ( - - - - Platform: {getPlatform()} {getPlatformVersion()} - - Bundle: {getBundle()} - {!isWeb() && ( - <> - Architecture: {getArchitecture()} - RN version: {getReactNativeVersion()} - RN runtime: {getRuntime()} - - )} - - {/* MarkdownTextInput singleline - */} - MarkdownTextInput multiline - setSelection(e.nativeEvent.selection)} - selection={selection} - /> - {/* TextInput singleline - */} - {/* TextInput multiline - */} - {JSON.stringify(value)} -