10play / 10tap-editor

React Native Rich Text Editor
MIT License
719 stars 29 forks source link

[BUG]: Editor isn't focusing / setting editable state #224

Closed anyaparekh closed 2 hours ago

anyaparekh commented 1 week ago

Describe the bug I've been using the editor with no issue up till today. But now, when trying to change or set editable / focus state it doesn't seem to be registering. This includes setting autofocus: true when initializing the editor.

To Reproduce I was able to reproduce the example with the basic example provided in the documentation:

import React from "react";
import {
  SafeAreaView,
  View,
  KeyboardAvoidingView,
  Platform,
  StyleSheet,
} from "react-native";
import { RichText, Toolbar, useEditorBridge } from "@10play/tentap-editor";

export default function Index() {
  const editor = useEditorBridge({
    autofocus: true,
    avoidIosKeyboard: true,
    initialContent,
  });

  return (
    <SafeAreaView style={exampleStyles.fullScreen}>
      <RichText editor={editor} />
      <KeyboardAvoidingView
        behavior={Platform.OS === "ios" ? "padding" : "height"}
        style={exampleStyles.keyboardAvoidingView}
      >
        <Toolbar editor={editor} />
      </KeyboardAvoidingView>
    </SafeAreaView>
  );
}

const exampleStyles = StyleSheet.create({
  fullScreen: {
    flex: 1,
  },
  keyboardAvoidingView: {
    position: "absolute",
    width: "100%",
    bottom: 0,
  },
});

const initialContent = `<p>This is a basic example!</p>`;

These are my dependencies:

"dependencies": {
    "@10play/tentap-editor": "^0.5.23",
    "@expo/vector-icons": "^14.0.2",
    "@react-navigation/bottom-tabs": "^7.0.0",
    "@react-navigation/native": "^7.0.0",
    "expo": "~52.0.11",
    "expo-blur": "~14.0.1",
    "expo-constants": "~17.0.3",
    "expo-font": "~13.0.1",
    "expo-haptics": "~14.0.0",
    "expo-linking": "~7.0.3",
    "expo-router": "~4.0.9",
    "expo-splash-screen": "~0.29.13",
    "expo-status-bar": "~2.0.0",
    "expo-symbols": "~0.2.0",
    "expo-system-ui": "~4.0.4",
    "expo-web-browser": "~14.0.1",
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-native": "0.76.3",
    "react-native-gesture-handler": "~2.20.2",
    "react-native-reanimated": "~3.16.1",
    "react-native-safe-area-context": "4.12.0",
    "react-native-screens": "~4.1.0",
    "react-native-web": "~0.19.13",
    "react-native-webview": "13.12.2"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@types/jest": "^29.5.12",
    "@types/react": "~18.3.12",
    "@types/react-test-renderer": "^18.3.0",
    "jest": "^29.2.1",
    "jest-expo": "~52.0.2",
    "react-test-renderer": "18.3.1",
    "typescript": "^5.3.3"
  },

Expected behavior In the above example the editor should auto-focus.

Any help would be greatly appreciated!!

17Amir17 commented 4 days ago

Hey! what version of react-native is this on?

anyaparekh commented 4 days ago

It's on RN version 0.76.3, but I think the issue is linked with react-native-webview as mentioned here. The below workaround solved my issue:

const [key, setKey] = useState('webview')

<RichText
    key={key}
    onLoad={() => setKey("reloadWebview")}
    ...
/>
GuySerfaty commented 4 days ago

@anyaparekh - thank you so much for referencing this, it solves another issue with hot reload on the expo setup, we will add this hacky and temporary solution on the next version