阿里千牛旺旺技术团队 关注
手机版

QAP实践:响应键盘显示、隐藏和其它高度变化事件

  1. 云栖社区>
  2. 阿里千牛旺旺技术团队>
  3. 博客>
  4. 正文

QAP实践:响应键盘显示、隐藏和其它高度变化事件

思禽 2017-06-27 22:22:45 浏览761 评论0

摘要: 'use strict'; import {createElement, Component, render, findDOMNode} from 'rax'; import {Link, View, Text, Input, TextInput, ScrollView, Button, Tra...

'use strict';

import {createElement, Component, render, findDOMNode} from 'rax';
import {Link, View, Text, Input, TextInput, ScrollView, Button, Transition} from 'nuke';
import QN from 'QAP-SDK';

class QAPKeyboardDemo extends Component {
    constructor(props) {
        super(props);

        this.state = {'viewBottom':'0'};

        QN.navigator.setTitle({
            query:{
                title: 'QAP键盘实践'
            }
        });

        QN.on('Global.KeyboardWillShow', (data) => {
            console.log('Global.KeyboardWillShow data : ', data);
            this.setState({viewBottom:data.height});

            // var orangeView = findDOMNode('orangeView');
            // console.log('orangeView : ', orangeView);
            // Transition(orangeView, {'transform':'translateY(-600)'}, {
            //     timingFunction: 'linear',
            //     delay: 0,
            //     duration: data.duration
            // }, function() {
            //     console.log('Transition done.');
            // });
        });

        QN.on('Global.KeyboardWillHide', (data) => {
            console.log('Global.KeyboardWillHide data : ', data);
            this.setState({viewBottom:data.height});
        });

        QN.on('Global.KeyboardWillChangeFrame', (data) => {
            console.log('Global.KeyboardWillChangeFrame data : ', data);
            this.setState({viewBottom:data.height});
        });
    }
    
    render() {
        return (
            <ScrollView style={styles.container} onScroll={this.hideKeyboard}>
                <TextInput 
                    ref='TextInput1' onInput={this.onInput}
                    style={styles.textInput} 
                    placeholder="请输入1" 
                    multiple={true}
                    value={this.state.inputValue}>
                </TextInput>
                <View id='orangeView' style={{backgroundColor:'orange', height:'100rem', position:'fixed', bottom:this.state.viewBottom}}>跟随键盘移动</View>
            </ScrollView>
        );
    }
}

const styles = {
    container: {
        flex: 1,
        backgroundColor: '#ffffff',
    },

    textInput: {
        borderStyle: 'solid',
        borderColor: 'lightblue',
        borderWidth: '1rem',
        width: '600rem',
        height: '200rem',
        'margin':'40rem'
    },
}

render(<QAPKeyboardDemo/>)

export default QAPKeyboardDemo;

qapkeyboard

【云栖快讯】你想见的Java技术专家都在这了,向大佬提问,有问题必答  详情请点击

网友评论