2016-11-17 46 views
1

我試圖在鍵盤處於活動狀態時縮短屏幕。但它總是在Android中進行奇怪的調整,它在iOS中工作正常。 鍵盤之前被激活:鍵盤是活動鍵盤出現時的高度調整在反應原生android中是錯誤的

後:

此:

我使用RN 0.37,這當我從頭開始也恰好是我的代碼:

import React from 'react'; 

import { 
    Keyboard, 
    Dimensions, 
    ScrollView, 
    StyleSheet, 
    Text, 
    TextInput, 
    AppRegistry 
} from 'react-native'; 

var {height, width} = Dimensions.get('window'); 
var _keyboardWillShowSubscription; 
var _keyboardWillHideSubscription; 
height = height - 20; 

class awesomeproject extends React.Component { 
    constructor(props) { 
     super(props); 
     this.state = { 
      height: height, 
     }; 
    } 
    componentDidMount() { 
     _keyboardWillShowSubscription = Keyboard.addListener('keyboardDidShow', (e) => this._keyboardWillShow(e)); 
     _keyboardWillHideSubscription = Keyboard.addListener('keyboardDidHide', (e) => this._keyboardWillHide(e)); 
    } 
    componentWillUnmount() { 
     _keyboardWillShowSubscription.remove(); 
     _keyboardWillHideSubscription.remove(); 
    } 
    _keyboardWillShow(e) { 
     this.setState({height: height - e.endCoordinates.height}); 
    } 
    _keyboardWillHide(e) { 
     this.setState({height: height}); 
    } 
    render() { 
    return (
     <View style={{height: this.state.height}}> 
      <View style={{backgroundColor: 'blue', flex: 1}} /> 
      <View style={styles.fieldBox}> 
       <TextInput 
        style={styles.field} 
        placeholder={'hello'} 
        autoCapitalize={'none'} 
        placeholderTextColor={'#afbccc'} 
        blurOnSubmit={false} 
        autoCorrect={false} 
        ref={'textinput'} 
        onChangeText={(data) => this.setState({message: data})} /> 
      </View> 
     </View> 
    ); 
    } 
} 

const styles = StyleSheet.create({ 
    field: { 
     color:'black', 
     fontWeight:'bold', 
     fontSize:18, 
     flex: 1, 
     marginHorizontal: 10 
    }, 
}); 

AppRegistry.registerComponent('awesomeproject',() => awesomeproject); 
+0

沒有ü找到一個解決方案?我認爲鍵盤的高度更多。我遇到了同樣的問題 – Vicky

回答

0

在andoird計算的高度是我越覺得我的。對於我的要求刪除e.endCorordinaets.height,並把它0

視圖自動調整大小在andorid.Soü不知道這個的setState在android系統。無需更改和oridid中的高度。它會自動工作,但我認爲需要在ios中工作。所以刪除更改高度並檢查視圖是否自動調整大小。

刪除此

this.setState({height: height - e.endCoordinates.height}); 
+0

嗨@Vicky,我通過完全刪除所有鍵盤事件並將android:windowSoftInputMode =「adjustResize」添加到我的Android Manifest android/app/src/main/AndroidManifest.xml中來修復它。只發生在Android上。 –

相關問題