(RN筆記)native-base ActionSheet 報錯處理

import React, { Component } from 'react';
import { View } from 'react-native';
import { ActionSheet, Button, Text } from 'native-base';

class Foo extends Component {
    constructor(props) {
         super(props);
         this.actionSheet = null;
    }

    render() {
         return (
             <View>
                 <Button onPress={() => this.showActionSheet()}>
                     <Text>Action Sheet!</Text>
                 </Button>
                 <ActionSheet ref={(c) => { this.actionSheet = c; }} />
             </View>
         );
    }

    showActionSheet() {
        if ( this.actionSheet !== null ) {
            // Call as you would ActionSheet.show(config, callback)
            this.actionSheet._root.showActionSheet({options: [1,2,3]}, (i) => 
console.log(i));
        }
    }
}

顯示                                   

 this.actionSheet._root.showActionSheet({ options: BUTTONS }, (i) => console.log(i) )

隱藏

this.actionSheet._root.hideActionSheet()

 

 

使用 native-base ActionSheet

經常會 報錯

cannot read property _root of null

cannot read property 'showactionsheet' of null

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章