2017-09-12 12 views
1

React Native for WebViewのテキストエディタコンポーネントを探しています。私は反応のネイティブ - zss - リッチテキストエディタを見つけましたが、それはひどいと思うWebViewを使用します。React Nativeテキストエディタコンポーネントはありますか?

IOSやAndroid用のNSAttributedStringとSpannableStringで動作するものを、Evernoteなどのネイティブな方法で見つけたいと考えています。ここで

Evernote Android app text editor

+0

を押したときに、あなたがこれを見て持っていなかったです! https://facebook.github.io/react-native/docs/textinput.html – Stophface

+0

そのTextInputだけで、ユーザーが色、フォント、下線などをアプリから直接変更できるようにする必要があります。 – sintylapse

+0

これは良い出発点であるはずです。あなた自身でいくつかの機能を追加する必要があるかもしれませんが、 'TextInput'がベースラインを提供します。 – Stophface

答えて

0

のTextInputをラップし、それを自動的にリサイズするTextAreaコンポーネント、あなたは「改行」ボタン

import React, { PropTypes } from 'react' 
import { TextInput } from 'react-native' 

export default class TextArea extends React.Component { 

    static propTypes = { 
     text: PropTypes.string.isRequired, 
     onChangeText: PropTypes.func.isRequired, 
     initialHeight: PropTypes.number, 
     isEditing: PropTypes.bool, 
     scrollViewRef: PropTypes.object, 
    } 

    static defaultProps = { 
     initialHeight: 40, 
     isEditing: true, 
     scrollViewRef: null, 
    } 

    state = { 
     height: this.props.initialHeight, 
    } 

    componentWillUnmount(){ 
     this._isUnmounted = false 
    } 

    focus(){ 
     this.refs.textInput.focus() 
    } 

    blur(){ 
     this.refs.textInput.blur() 
    } 

    _contentSizeChanged = e => { 
     this.setState({ 
      height: e.nativeEvent.contentSize.height, 
     },() => { 
      if (this.props.scrollViewRef) { 
       setTimeout(() => { 
        if (!this._isUnmounted) this.props.scrollViewRef.scrollToEnd() 
       }, 0) 
      } 
     }) 
    } 

    _onChangeText = text => { 
     this.props.onChangeText(text) 
    } 

    render(){ 
     return (
      <TextInput 
       ref = "textInput" 
       multiline 
       value = {this.props.text} 
       style = {{ height: this.state.height, color: 'black', flex: 1 }} 
       onChangeText = {this._onChangeText} 
       onContentSizeChange = {this._contentSizeChanged} 
       editable = {this.props.isEditing} 
       blurOnSubmit = {false} 
      /> 
     ) 
    } 

} 
+0

で私のコンポーネントを投稿しましたこれは本当に "テキストエディタ"の実装についてのあなたの質問に答えますか?実際のテキスト編集部分も実装しましたか?もしそうなら、分かち合う気に? – chapeljuice

+0

これは私が実装した解決策です。なぜ私は他の部分を実装しないことに決めたのか忘れてしまった – sintylapse

関連する問題