Cocina

Cocina

  • 文档
  • UI组件
  • API
  • 帮助
  • 博客

›组件

起步

  • 集合

组件

  • 结构
  • 手风琴
  • 浮动弹层
  • 角标
  • 按钮
  • 卡片
  • 复选框
  • 日期选择
  • 滑动的卡片
  • 浮动按钮
  • 底部选项卡
  • 表单
  • 顶部栏
  • 图标
  • 列表
  • 选择器
  • 单选
  • 搜索栏
  • 分段器
  • 加载器
  • 缩略图
  • 吐司
  • 标题大小
  • 抽屉滑动
  • 关联组件

关联组件

Ref关联组件

NativeBase构建于React Native之上。因此,NativeBase的组件各自具有替换React Native元素。 NativeBase现在使开发人员可以轻松地使用ref访问其任何组件,以及相关的React Native元素。 在构建组件之后,您可能会发现自己想要伸出并调用从render()返回的组件实例上的方法。 这可以通过refs来实现。Refs是向特定子实例发送消息的好方法。 该REF属性需要一个回调函数,该组件被安装或卸载之后立即回调将被执行。

句法

import React, { Component } from 'react';
import { Container, Header, Content, Button } from 'native-base';
export default class RefExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <Button ref={ (c) => this._button = c }>
            Click Me
          </Button>
        </Content>
      </Container>
    );
  }
}

this._button 为您提供NativeBase Button的参考。 this._button._root 为您提供NativeBase Button替换React Native元素的引用,即TouchableOpacity。 所有NativeBase组件都可以访问此功能。

← Previous
  • Ref关联组件
Cocina
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2019 Your Name or Your Company Name