Giter VIP home page Giter VIP logo

Comments (6)

benevbright avatar benevbright commented on May 16, 2024 2

Hi, @tomtom94
I have to say to you I'm sorry.
The module was passing wrong props to extraHeaderComponent.
I fixed it and published 0.2.13.
Please update your module to 0.2.13.

And I updated example.
Please check Expo Snack or /example/src/ExtraHeaderScreen.js

You can close this issue after you checked it's working.

from react-navigation-collapsible.

benevbright avatar benevbright commented on May 16, 2024 2

And I also looked the issue you said it's not working with Component class.
Yes, it was working only with the stateless component.

I fixed it and updated to 0.2.14.
Now it supports extra header to use class component.
Thanks very much for your issue. @tomtom94

from react-navigation-collapsible.

tomtom94 avatar tomtom94 commented on May 16, 2024 1

It works like a charm, thanks a lot. This module is simple & awesome.

Bye.

from react-navigation-collapsible.

tomtom94 avatar tomtom94 commented on May 16, 2024

I just took your example at this page https://github.com/benevbright/react-navigation-collapsible/blob/master/example/src/ExtraHeaderScreen.js

And I made some light modifications in order to put a setState on the search bar.


import React, { Component } from "react";
import { Text, FlatList, View, Animated, TouchableOpacity } from "react-native";

import { withCollapsible } from "react-navigation-collapsible";

const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);

class ExtraHeaderScreen extends Component {
  static navigationOptions = {
    title: "Extra Header"
  };

  constructor(props) {
    super(props);

    const data = [];
    for (let i = 0; i < 60; i++) {
      data.push(i);
    }

    this.state = {
      data: data,
      searchBar: "" // <---------- I wanna get the query of the search
    };
  }

  renderItem = ({ item }) => (
    <TouchableOpacity
      onPress={() => {
        this.props.navigation.navigate("DetailScreen");
      }}
      style={{
        width: "100%",
        height: 50,
        borderBottomColor: "#0002",
        borderBottomWidth: 0.5,
        paddingHorizontal: 20,
        justifyContent: "center"
      }}
    >
      <Text style={{ fontSize: 22 }}>{item}</Text>
    </TouchableOpacity>
  );

  render() {
    const { paddingHeight, scrollY, onScroll } = this.props.collapsible;

    return (
      <AnimatedFlatList
        style={{ flex: 1 }}
        data={this.state.data}
        renderItem={this.renderItem}
        keyExtractor={(item, index) => String(index)}
        contentContainerStyle={{ paddingTop: paddingHeight }}
        scrollIndicatorInsets={{ top: paddingHeight }}
        onScroll={onScroll}
        _mustAddThis={scrollY}
      />
    );
  }
}

const objExtraHeaderScreen = new ExtraHeaderScreen(); // <---------- In order to access the class above

const ExtraHeader = (/*{navigation}*/) => (
  <View
    style={{
      width: "100%",
      height: "100%",
      paddingHorizontal: 20,
      paddingVertical: 10
    }}
  >
    <View
      style={{
        backgroundColor: "white",
        flex: 1,
        borderRadius: 15,
        justifyContent: "center",
        alignItems: "center"
      }}
    >
      <Text
        style={{ color: "gray" }}
        onPress={() => {
          objExtraHeaderScreen.setState({ searchBar: "what's up guys ?" }); // <---------- The simple setState because it is necessary to put a setState if there is a search bar ;)
        }}
      >
        Search Here
      </Text>
    </View>
  </View>
);

const collapsibleParams = {
  extraHeader: ExtraHeader,
  extraHeaderStyle: {
    height: 50,
    backgroundColor: "#061"
  }
};

export default withCollapsible(ExtraHeaderScreen, collapsibleParams);

Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to this.state directly or define a state = {}; class property with the desired state in the ExtraHeaderScreen component.

from react-navigation-collapsible.

benevbright avatar benevbright commented on May 16, 2024

Hi, @tomtom94
Because ExtraHeader is not a child component of your screen component, you can't use this.setState.
You need to communicate between your screen and ExtraHeader with usingnavigation prop, which is the same way you communicate with react-navigation's header button.

So, instead this.setState, you need to use navigation.setParams and naviagtion.getParam.

I'll improve the example as you were going to try.

from react-navigation-collapsible.

tomtom94 avatar tomtom94 commented on May 16, 2024

Thanks for your answer, it seems to be the solution ;)

However I tried something on your code example but it doesn't work yet (see below)

const ExtraHeader = ({ navigation }) => (
  <View
    style={{
      width: "100%",
      height: "100%",
      paddingHorizontal: 20,
      paddingVertical: 10
    }}
  >
    <View
      style={{
        backgroundColor: "white",
        flex: 1,
        borderRadius: 15,
        justifyContent: "center",
        alignItems: "center"
      }}
    >
      <Text
        style={{ color: "gray" }}
        onPress={() => {
          navigation.setParams({ ok: "ok" });
        }}
      >
        Search Here
      </Text>
    </View>
  </View>
);

error message : Undefined is not an object (evaluating 'navigation.setParams')

I like this module a lot but, do you have any clue ?

from react-navigation-collapsible.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.