Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput: multiline rich content support #1023

Open
necolas opened this issue Jul 7, 2018 · 11 comments
Open

TextInput: multiline rich content support #1023

necolas opened this issue Jul 7, 2018 · 11 comments
Labels
project:react-native-web Issue associated with react-native-web

Comments

@necolas
Copy link
Owner

necolas commented Jul 7, 2018

Multiline TextInput in React Native supports components as children. Along with #795 and #793, this may require switching to contentEditable for the multiline implementation, if not the single-line input.

@ollyde
Copy link

ollyde commented Dec 6, 2018

Slate doesn't play so nice with mobile unfortunately. Same with DraftJS.

The easiest solution is just wrap each one in it's own native renderer function that spits out the following:

SubComponent

<Text>
     <Text style={{ fontWeight: 'bold' }}>Starts </Text>bold.
</Text>

Web

<p contentEditable={true} onKeyDown={(e) => this.onChange(e)}>
    <SubComponent />
</p>

Mobile

<TextInput 
    multiline={true} 
    onChange={(e) => this.onChange(e)}
>
    <SubComponent />
</TextInput>

PS Really awesome library I'm using this to create cross platform apps (Web, Electron, React-Native) and it's going epic. Wish I could donate!

@necolas
Copy link
Owner Author

necolas commented Dec 6, 2018

@voidstarfire Thanks! How does React manage when a user edits the contentEditable content that is produced by components React renders? I heard that was one of the difficulties with contentEditable but haven't made time to experiment myself yet. Any more feedback you can include would be really helpful

@ollyde
Copy link

ollyde commented Dec 6, 2018

I'm playing with that just now.

It seems to work really well so far. The <Text/> components just wrap around the text. As long as you stick with <Text> only components. No views.

Seems we have to create some sort of generator to filter out empty text components and fill in styled ones. Should work well with React-native-web.

I will get back probably mid next week with my results :-)

Here's some examples if you're interested. @necolas

I'm actually creating a cross-platform native Markdown editor (Not just viewer) from scratch in React.

Sub component.

export default class Editor extends React.Component<Props, State> {
    render () {
        return (
            <Text>
                <Text>{'This is a sentence' + '\n'}</Text>
                <Text style={{fontWeight: "bold"}}> with</Text>
                <Text>one word in bold</Text>
            </Text>
        )
    }
}

Mobile

export default class MobileRender extends React.Component<Props, State> {
    render() {
        return (
            <TextInput 
                 multiline={true} 
                 style={{ flex: 1, alignSelf: 'stretch' }}
                 onChange={(e) => this.onChange(e)}
             >
                 <Editor
                     markdown={testMarkdown}
                 />
            </TextInput>
        )
    }
    onChange = (event: NativeSyntheticEvent<any>) => {
        const {name, type, value} = event.nativeEvent;
        debugger
    }
}

Desktop / Web

export default class WebRender extends React.Component<Props, State> {
    constructor(props: Props) {
        super(props)
    }
    render() {
        return (
            <p contentEditable={true} onKeyDown={(e) => this.onChange(e)}>
                <Editor
                    markdown={testMarkdown}
                />
            </p>
        )
    }

    onChange = (event: React.SyntheticEvent<KeyboardEvent>) => {
        
    }
}

@necolas
Copy link
Owner Author

necolas commented Dec 6, 2018

Seems we have to create some sort of generator to filter out empty text components and fill in styled ones.

What does that mean?

@ollyde
Copy link

ollyde commented Dec 6, 2018

@necolas My bad I was speaking from a Markdown perspective mostly.

Speaking from a <TextInput> only perspective it seems to work pretty well. The react-native-web <Text> components stack fine and inside contentEditable they seem to work with styles just fine, even when backspacing until you have no content. Although I imagine there will be a lot of empty <Text>{wasContent}</Text> around; hence some sort of filter.

@shakeabi
Copy link

@OllyDixon How is the development going?

@ollyde
Copy link

ollyde commented Jul 11, 2019

@shakeabi I'm using a library called Quill, worked great for mobile and web :-)

@shakeabi
Copy link

@OllyDixon How are you using quilljs in native cuz there's no native supported quill yet, right? (If webview, then though it may work for various devices, it's still not purely native and can have unexpected behaviour)

@ollyde
Copy link

ollyde commented Jul 11, 2019

@shakeabi there was no native solution that included an editor.

@shakeabi
Copy link

@OllyDixon It's not that difficult to make a simple native rich text editor. My (partial) solution includes using nested inside . However, react-native-web doesn't support this as it renders either textarea or input tags (neither of them supports children tags). #1380: I've discussed the same in this issue. A probable solution would be to replace the TextInput version (textarea or input) react-native-web to content-editable divs.

@ollyde
Copy link

ollyde commented Jul 11, 2019

@shakeabi yes I discovered this as well. I no longer do React Native anymore though. Flutter is much better :-)

@necolas necolas added the project:react-native-web Issue associated with react-native-web label Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project:react-native-web Issue associated with react-native-web
Projects
None yet
Development

No branches or pull requests

3 participants