ネイティブルータフラックスを反応させる:オーバーライドは、コンポーネントおよびアクセスローカル関数内で左または右ボタン

初心者009

コンポーネント内のボタンをオーバーライドすることはできましたが、ローカル関数を呼び出すことができませんでした。たとえば、「更新」を押しても何も起こりません。これは、ボタンのテキストを上書きして機能を実行するための正しい方法です。あなたのヘルプは感謝です。ありがとう。

import { WebView } from 'react-native'
import React, { PropTypes, Component } from 'react';
import { View, Text } from 'react-native';

import styles from '../src/styles/home'

var WEBVIEW_REF = 'webview';
class WebViewComponent extends Component {

  static rightTitle = "Refresh";
  static onRight() {
    this.reload;
  }

  static propTypes = {
    url: PropTypes.string,
    scalesPageToFit: PropTypes.bool,
    startInLoadingState: PropTypes.bool,
  };

  static defaultProps = {
    url: 'http://google.com',
    scalesPageToFit: true,
    startInLoadingState: true,
  };

  render() {
    return (
      <WebView
          ref={ WEBVIEW_REF }
          style={ { flex: 1, marginTop: 50 } }
          source={ { uri: this.props.url } }
          scalesPageToFit={ this.props.scalesPageToFit }
          startInLoadingState={ this.props.startInLoadingState } />
      );
  }

  reload = () => {
    alert('reload');
  };

}

module.exports = WebViewComponent;
初心者009

私はいくつかの調査の後に答えを得ます、静的を使用しないでください、componentDidMount()を使用してください

import { WebView } from 'react-native'
import React, { PropTypes, Component } from 'react';
import { View, Text } from 'react-native';

import styles from '../src/styles/home'

var WEBVIEW_REF = 'webview';
class WebViewComponent extends Component {

  //here is the answer
  componentDidMount() {
    Actions.refresh({rightTitle: 'Refresh', onRight: this.reload})
  }

  static propTypes = {
    url: PropTypes.string,
    scalesPageToFit: PropTypes.bool,
    startInLoadingState: PropTypes.bool,
  };

  static defaultProps = {
    url: 'http://google.com',
    scalesPageToFit: true,
    startInLoadingState: true,
  };

  render() {
    return (
      <WebView
          ref={ WEBVIEW_REF }
          style={ { flex: 1, marginTop: 50 } }
          source={ { uri: this.props.url } }
          scalesPageToFit={ this.props.scalesPageToFit }
          startInLoadingState={ this.props.startInLoadingState } />
      );
  }

  reload = () => {
    alert('reload');
  };

}

module.exports = WebViewComponent;

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ