Comments (6)
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.
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.
It works like a charm, thanks a lot. This module is simple & awesome.
Bye.
from react-navigation-collapsible.
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.
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.
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)
- Example doesn't run. Error "Couldn't find a route object"
- Support with react-native-maps HOT 6
- Headerbar does not rerender after changing options HOT 1
- Can we have animation when calling showHeader ? HOT 1
- Can we collapsible header for tabs ? HOT 3
- Change header title HOT 4
- Error when installing newest version HOT 3
- SubHeader will move up after pulling down. HOT 1
- TypeError: undefined is not an object (evaluating 'this._callListeners.bind') HOT 1
- React Navigation 6.x Support HOT 1
- v6.0.0 default project broken HOT 1
- Transparent header HOT 1
- Can a header enlarge itself HOT 1
- Collapse as soon as scrolling starts HOT 2
- Possible to use collapsible subheader with collapsible header? HOT 1
- containerPaddingTop is not working properly for expo project, with temporary fix HOT 1
- Project is using deprecated .expo.* file extensions HOT 3
- Why header appear when scroll reachs bottom of current view ? HOT 1
- Error on require react-native-iphone-x-helper "undefined is not an object"
- Inconsistency between ios and Android
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-navigation-collapsible.