Yêu cầu thg 1 22, 2019 2:09 SA 719 0 1
  • 719 0 1
+1

show beginning of text in input react native

Chia sẻ
  • 719 0 1

Mọi người cho mình hỏi chút với ạ.

Mình đang làm về React native mà khi nhập chữ vào Input Text khi chữ quá dài và mình chuyển sang dòng Input Text khác thì dòng chữ ở InputText trên lại Không hiển thị từ phần đầu mà lại hiển thị từ phần cuối.

Làm sao để cho nó hiển thị từ phần đầu nếu dòng chữ quá Dài ạ.

Thank mọi người Giúp đỡ

1 CÂU TRẢ LỜI


Đã trả lời thg 1 23, 2019 1:23 SA
+1

Bạn có thể thêm ellipsizeMode="head" hoặc ellipsizeMode="tail" nhá

Chia sẻ
thg 1 23, 2019 1:31 SA

Hoặc bạn có thể thử cách này, khi gõ xong thì setState về ban đầu, Good luck!!

import React, { Component } from 'react';
import { AppRegistry,View, TextInput,Text } from 'react-native';

export default class UselessTextInput extends Component {
  constructor(props) {
    super(props);
    this.state = { text: 'Initial Placeholder' , textTwo:'Initial Two'};
  }

  render() {
    return (
      <View>
      <Text>
        text: {this.state.text}
        </Text> 
              <Text>
        textTwo: {this.state.textTwo}
        </Text>
      <TextInput
        style={{height: 40, borderColor: 'gray', borderWidth: 1}}
        onChangeText={this.onChangeText.bind(this)}
      />
      <TextInput
        style={{height: 40, borderColor: 'gray', borderWidth: 1}}
        onChangeText={this.onChangeTextTwo.bind(this)}
      />
      </View>
    );
  }
  
  onChangeText(text){
    this.setState({text})
  }
  
  onChangeTextTwo(text){
    this.setState({textTwo:text})
  }
}
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí