簡體   English   中英

React-Native按鈕環繞,一個按鈕

[英]React-Native button wrapping, a button

我正在嘗試包裝一個具有recordActivityTag功能的recordActivityTag 目前,它的工作方式不是從第一個按鈕捕獲數據功能。 我需要在整個應用程序中關注標簽。 這就是為什么我構造了recordActivityTag的原因。 該功能適用​​於事件,但按鈕除外。

如何在onPress (如果可能)中調用另一個屏幕上的按鈕上的操作? 我知道我需要將外部道具傳遞給TouchableOpacity,然后調用另一個按鈕。

import * as React from "react";
import { Core } from "common";
import { TouchableOpacity } from "react-native";

interface BtnProps {
  readonly data: string
  readonly recordActivityTag:(tag: Core.ActivityTag) => void
}

export default class Button extends React.Component<BtnProps, {}> {
  constructor(props: BtnProps) {
    super(props);
  }

  render() {
    const { recordActivityTag } = this.props;
    return (
      <TouchableOpacity>
        onPress {() => recordActivityTag}
        {this.props.children}
      </TouchableOpacity>
    );
  }
}

請確保你給你的函數的onPress中的道具TouchableOpacity組成部分,而且你實際調用recordActivityTag內它。

export default class Button extends React.Component<BtnProps, {}> {
  render() {
    const { recordActivityTag } = this.props;
    return (
      <TouchableOpacity onPress={() => recordActivityTag()}>
        {this.props.children}
      </TouchableOpacity>
    );
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM