P
P
pcdesign2019-03-17 10:26:11
React Native
pcdesign, 2019-03-17 10:26:11

How can I put this code into a separate Header.js file?

There is such an example.
https://snack.expo.io/@satya164/github.com-callsta...
And the file ./src/AppbarExample.js
This file changes the title before rendering.
That is, the title is custom.

static title = 'Appbar';
  static navigationOptions = ({ navigation }) => {
    const params = { ...initialParams, ...navigation.state.params };

    return {
      header: (
        <Appbar.Header>
          {params.showLeftIcon && (
            <Appbar.BackAction onPress={() => navigation.goBack()} />
          )}
          <Appbar.Content
            title="Title"
            subtitle={params.showSubtitle ? 'Subtitle' : null}
          />
          {params.showSearchIcon && (
            <Appbar.Action icon="search" onPress={() => {}} />
          )}
          {params.showMoreIcon && (
            <Appbar.Action icon={MORE_ICON} onPress={() => {}} />
          )}
        </Appbar.Header>
      ),
    };
  };

How can I move this code into a separate Header.js file so that it can be used in other places?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alexandrovich, 2019-03-17
@pcdesign

like this?
https://snack.expo.io/rk3QN2oP4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question