From 9b7f5a3edebef2b754137ac95abe8878785163e7 Mon Sep 17 00:00:00 2001 From: The_Kohan Date: Mon, 14 Oct 2024 16:41:43 +0200 Subject: [PATCH 1/5] feat: draft example app --- example/babel.config.js | 1 + example/ios/Podfile.lock | 246 ++++- example/package.json | 12 +- example/src/App.tsx | 376 +++++--- example/src/components/ColorPickerInput.tsx | 65 ++ example/src/components/IterableInput.tsx | 45 + example/src/components/index.ts | 2 + .../AboutExample.tsx} | 5 +- .../src/examples/MarkdownPreviewExample.tsx | 113 +++ example/src/examples/PlaygroundExample.tsx | 184 ++++ example/src/examples/index.ts | 27 + example/tsconfig.json | 3 +- yarn.lock | 852 +++++++++++++++++- 13 files changed, 1787 insertions(+), 144 deletions(-) create mode 100644 example/src/components/ColorPickerInput.tsx create mode 100644 example/src/components/IterableInput.tsx create mode 100644 example/src/components/index.ts rename example/src/{PlatformInfo.tsx => examples/AboutExample.tsx} (96%) create mode 100644 example/src/examples/MarkdownPreviewExample.tsx create mode 100644 example/src/examples/PlaygroundExample.tsx create mode 100644 example/src/examples/index.ts diff --git a/example/babel.config.js b/example/babel.config.js index d9addbba..353c7d44 100644 --- a/example/babel.config.js +++ b/example/babel.config.js @@ -13,5 +13,6 @@ module.exports = { }, }, ], + 'react-native-reanimated/plugin', ], }; diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 41b50600..757d99e9 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1237,6 +1237,72 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga + - react-native-safe-area-context (4.11.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - react-native-safe-area-context/common (= 4.11.0) + - react-native-safe-area-context/fabric (= 4.11.0) + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - react-native-safe-area-context/common (4.11.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - react-native-safe-area-context/fabric (4.11.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - react-native-safe-area-context/common + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga - React-nativeconfig (0.75.2) - React-NativeModulesApple (0.75.2): - glog @@ -1497,7 +1563,71 @@ PODS: - React-logger (= 0.75.2) - React-perflogger (= 0.75.2) - React-utils (= 0.75.2) - - RNLiveMarkdown (0.1.143): + - RNCAsyncStorage (2.0.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - RNGestureHandler (2.20.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - RNLiveMarkdown (0.1.161): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - RNLiveMarkdown/common (= 0.1.161) + - Yoga + - RNLiveMarkdown/common (0.1.161): - DoubleConversion - glog - hermes-engine @@ -1517,9 +1647,8 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - - RNLiveMarkdown/common (= 0.1.143) - Yoga - - RNLiveMarkdown/common (0.1.143): + - RNReanimated (3.15.4): - DoubleConversion - glog - hermes-engine @@ -1539,6 +1668,95 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core + - RNReanimated/reanimated (= 3.15.4) + - RNReanimated/worklets (= 3.15.4) + - Yoga + - RNReanimated/reanimated (3.15.4): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - RNReanimated/worklets (3.15.4): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - RNScreens (3.34.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-RCTImage + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - RNScreens/common (= 3.34.0) + - Yoga + - RNScreens/common (3.34.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-RCTImage + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core - Yoga - SocketRocket (0.7.0) - Yoga (0.0.0) @@ -1581,6 +1799,7 @@ DEPENDENCIES: - React-logger (from `../node_modules/react-native/ReactCommon/logger`) - React-Mapbuffer (from `../node_modules/react-native/ReactCommon`) - React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`) + - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - React-nativeconfig (from `../node_modules/react-native/ReactCommon`) - React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) @@ -1607,7 +1826,11 @@ DEPENDENCIES: - React-utils (from `../node_modules/react-native/ReactCommon/react/utils`) - ReactCodegen (from `build/generated/ios`) - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) + - "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)" + - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) - RNLiveMarkdown (from `../..`) + - RNReanimated (from `../node_modules/react-native-reanimated`) + - RNScreens (from `../node_modules/react-native-screens`) - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) SPEC REPOS: @@ -1686,6 +1909,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon" React-microtasksnativemodule: :path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks" + react-native-safe-area-context: + :path: "../node_modules/react-native-safe-area-context" React-nativeconfig: :path: "../node_modules/react-native/ReactCommon" React-NativeModulesApple: @@ -1738,8 +1963,16 @@ EXTERNAL SOURCES: :path: build/generated/ios ReactCommon: :path: "../node_modules/react-native/ReactCommon" + RNCAsyncStorage: + :path: "../node_modules/@react-native-async-storage/async-storage" + RNGestureHandler: + :path: "../node_modules/react-native-gesture-handler" RNLiveMarkdown: :path: "../.." + RNReanimated: + :path: "../node_modules/react-native-reanimated" + RNScreens: + :path: "../node_modules/react-native-screens" Yoga: :path: "../node_modules/react-native/ReactCommon/yoga" @@ -1779,6 +2012,7 @@ SPEC CHECKSUMS: React-logger: 8db32983d75dc2ad54f278f344ccb9b256e694fc React-Mapbuffer: 1c08607305558666fd16678b85ef135e455d5c96 React-microtasksnativemodule: f13f03163b6a5ec66665dfe80a0df4468bb766a6 + react-native-safe-area-context: f1fda705dfe14355f41933debb5932887e234cc5 React-nativeconfig: 57781b79e11d5af7573e6f77cbf1143b71802a6d React-NativeModulesApple: 7ff2e2cfb2e5fa5bdedcecf28ce37e696c6ef1e1 React-perflogger: 8a360ccf603de6ddbe9ff8f54383146d26e6c936 @@ -1805,7 +2039,11 @@ SPEC CHECKSUMS: React-utils: 81a715d9c0a2a49047e77a86f3a2247408540deb ReactCodegen: 60973d382704c793c605b9be0fc7f31cb279442f ReactCommon: 6ef348087d250257c44c0204461c03f036650e9b - RNLiveMarkdown: e44918843c2638692348f39eafc275698baf0444 + RNCAsyncStorage: 597673c6086d359029afefef8fd5859f1f35ab87 + RNGestureHandler: c374c750a0a9bacd95f5c740d146ab9428549d6b + RNLiveMarkdown: 96442a72695a546e2ee0928e50e58f9894280586 + RNReanimated: e94c6ad6b7a23ff641da13ada7d405c65f2c45f1 + RNScreens: de6e57426ba0e6cbc3fb5b4f496e7f08cb2773c2 SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: 2a45d7e59592db061217551fd3bbe2dd993817ae diff --git a/example/package.json b/example/package.json index 6dd71838..5d03db2e 100644 --- a/example/package.json +++ b/example/package.json @@ -9,8 +9,18 @@ "start": "react-native start" }, "dependencies": { + "@gorhom/bottom-sheet": "^5", + "@react-native-async-storage/async-storage": "^2.0.0", + "@react-navigation/native": "^6.1.18", + "@react-navigation/native-stack": "^6.11.0", + "@react-navigation/stack": "^6.4.1", "react": "18.3.1", - "react-native": "0.75.2" + "react-native": "0.75.2", + "react-native-gesture-handler": "^2.20.0", + "react-native-reanimated": "^3.15.4", + "react-native-safe-area-context": "^4.11.0", + "react-native-screens": "^3.34.0", + "reanimated-color-picker": "^3.0.4" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/example/src/App.tsx b/example/src/App.tsx index 7e29fee9..567764d3 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,151 +1,263 @@ +import { + HeaderBackButton, + type HeaderBackButtonProps, +} from '@react-navigation/elements'; +import type { + NavigationProp, + NavigationState, + PathConfigMap, +} from '@react-navigation/native'; import * as React from 'react'; -import {Button, StyleSheet, Text, View} from 'react-native'; -import {MarkdownTextInput} from '@expensify/react-native-live-markdown'; -import type {TextInput} from 'react-native'; -import * as TEST_CONST from './testConstants'; -import {PlatformInfo} from './PlatformInfo'; +import { + ActivityIndicator, + FlatList, + Linking, + Platform, + Pressable, + ScrollView, + StyleSheet, + Text, + View, +} from 'react-native'; -export default function App() { - const [value, setValue] = React.useState(TEST_CONST.EXAMPLE_CONTENT); - const [textColorState, setTextColorState] = React.useState(false); - const [linkColorState, setLinkColorState] = React.useState(false); - const [textFontSizeState, setTextFontSizeState] = React.useState(false); - const [emojiFontSizeState, setEmojiFontSizeState] = React.useState(false); - const [selection, setSelection] = React.useState({start: 0, end: 0}); - - const style = React.useMemo(() => { - return { - color: textColorState ? 'gray' : 'black', - fontSize: textFontSizeState ? 15 : 20, - }; - }, [textColorState, textFontSizeState]); +import {NavigationContainer, useNavigation} from '@react-navigation/native'; - const markdownStyle = React.useMemo(() => { - return { - emoji: { - fontSize: emojiFontSizeState ? 15 : 20, - }, - link: { - color: linkColorState ? 'red' : 'blue', +import AsyncStorage from '@react-native-async-storage/async-storage'; +import { + createNativeStackNavigator, + type NativeStackNavigationProp, +} from '@react-navigation/native-stack'; +import { + createStackNavigator, + type StackNavigationProp, +} from '@react-navigation/stack'; +import {GestureHandlerRootView, RectButton} from 'react-native-gesture-handler'; +import {EXAMPLES} from './examples'; +import {useReducedMotion} from 'react-native-reanimated'; +import {BottomSheetModalProvider} from '@gorhom/bottom-sheet'; +import {SafeAreaProvider} from 'react-native-safe-area-context'; + +function noop() { + // do nothing +} + +type RootStackParamList = {[P in keyof typeof EXAMPLES]: undefined} & { + Home: undefined; +}; + +interface HomeScreenProps { + navigation: + | StackNavigationProp + | NativeStackNavigationProp; +} + +const EXAMPLES_NAMES = Object.keys(EXAMPLES); + +function HomeScreen({navigation}: HomeScreenProps) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const [wasClicked, setWasClicked] = React.useState([]); + + return ( + ( + { + navigation.navigate(name); + if (!wasClicked.includes(name)) { + setTimeout(() => setWasClicked([...wasClicked, name]), 500); + } + }} + wasClicked={wasClicked.includes(name)} + /> + )} + renderScrollComponent={props => } + ItemSeparatorComponent={ItemSeparator} + style={styles.list} + /> + ); +} + +interface ItemProps { + icon?: string; + title: string; + onPress: () => void; + missingOnFabric?: boolean; + wasClicked?: boolean; +} + +function Item({icon, title, onPress, wasClicked}: ItemProps) { + const Button = Platform.OS === 'macos' ? Pressable : RectButton; + return ( + + ); +} + +function ItemSeparator() { + return ; +} + +const Stack = + Platform.OS === 'macos' + ? createStackNavigator() + : createNativeStackNavigator(); + +const linking = { + prefixes: [], + config: { + screens: EXAMPLES_NAMES.reduce>( + (acc, name) => { + acc[name] = name; + return acc; }, - }; - }, [emojiFontSizeState, linkColorState]); + {Home: ''}, + ), + }, +}; - // TODO: use MarkdownTextInput ref instead of TextInput ref - const ref = React.useRef(null); +function BackButton(props: HeaderBackButtonProps) { + const navigation = useNavigation>(); return ( - - - setSelection(e.nativeEvent.selection)} - selection={selection} - id={TEST_CONST.INPUT_ID} - /> - {JSON.stringify(value)} - + ); } @@ -175,8 +170,6 @@ export default function App() { [], ); - const shouldReduceMotion = useReducedMotion(); - if (!isReady) { return ( @@ -186,43 +179,34 @@ export default function App() { } return ( - - - - {/* */} - {/* */} - - - null : undefined, - }} - /> - {EXAMPLES_NAMES.map(name => ( - - ))} - - - - - + + + null : undefined, + }} + /> + {EXAMPLES_NAMES.map(name => ( + + ))} + + ); } diff --git a/example/src/components/ColorPickerInput.tsx b/example/src/components/ColorPickerInput.tsx deleted file mode 100644 index 5cc66f56..00000000 --- a/example/src/components/ColorPickerInput.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import React from 'react'; -import {TouchableOpacity, StyleSheet, Button} from 'react-native'; -import {BottomSheetModal, BottomSheetView} from '@gorhom/bottom-sheet'; -import ColorPicker, {HueSlider, Panel1} from 'reanimated-color-picker'; - -type ColorPickerInputProps = { - color?: string; - onChangeColor: (color: string) => void; -}; - -export const ColorPickerInput: React.FC = ({ - color = '#000000', - onChangeColor, -}) => { - const bottomSheetModalRef = React.useRef(null); - - const openModal = React.useCallback(() => { - bottomSheetModalRef.current?.present(); - }, []); - - return ( - <> - - - - onChangeColor(color.hex)} - style={styles.colorPicker}> - - - -