使用 native-base ActionSheet

经常会 报错

cannot read property _root of null

cannot read property 'showactionsheet' of null

可在页面初始化此组件 通过ref绑定调用组件

<ActionSheet ref={(c) => { this.actionSheet = c; }} />

显示                                   

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

隐藏

this.actionSheet._root.hideActionSheet()

代码如下

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 ) {
            this.actionSheet._root.showActionSheet({options: [1,2,3]}, (i) => 
            console.log(i));
        }
    }
}

 

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐