Comments (8)
@evanmrose It is actually very easy to do. Since navBar is a component and you are rendering it on top of your View, what you can do is change the height of navBar to 0 if user scroll down and as soon as user scroll up change it back to normal.
You can also add a little bit of animation for make it a little bit smooth.
renderScene(route, navigator) {
const Component = route.component;
let navBar = route.navigationBar;
const { hideNavBar } = this.state;
let navBarStyle = hideNavBar? { height: 0 } : {};
if (navBar) {
navBar = React.addons.cloneWithProps(navBar, { navigator, route, style: {...navBarStyle} });
}
return (
<View style={{flex: 1}}>
{navBar}
<Component style={{flex: 1, backgroundColor: 'green'}}/>
</View>
);
}
You can also make the navBar
null if hideNavBar
is true
.
from react-native-navbar.
@jeremiecarlson, You need to trigger animation at one point, either 0 or x. You have to do some test with Animated
apis. Below is a simple example how you would animate height.
class MyAwesomeComponent extends Component {
constructor(props) {
super(props);
this.height = new Animated.Value(100);
}
_setAnimation(enable) {
Animated.timing(this.height, {
duration: 400,
toValue: enable? 100 : 0
}).start()
}
render() {
return (
<Animated.View style={{ height: this.height }}/>
);
}
}
So at some point you need to call this._setAnimation
and pass hide or show state into it. One thing to remember is that Animated
is not calling the re-render of your component any more. It does it internally.
Also if you need to create an Animated component from one of your custom component you can use createAnimatedComponent method.
from react-native-navbar.
Hi there! Hm, no, at the moment we don't have any API for that. But it's a good point I think.
from react-native-navbar.
I'll close it until any feedback.
from react-native-navbar.
@alinz I was wondering if you could expand on how you might animate that height?
from react-native-navbar.
@alinz Thanks for your response!
from react-native-navbar.
What if the scroll-view from which the events which trigger / drive the hiding of the header come from, is deep inside the hierarchy of components inside the navigator?
I am using NavigationExperimental...
from react-native-navbar.
@gorjanz Try to use Panresponder API. Here is solution that works for me:
- For View component which you want to trigger swipe set panResponder according to docs like below:
componentWillMount() {
this._panResponder = PanResponder.create({
onStartShouldSetPanResponder: (evt, gestureState) => false,
onStartShouldSetPanResponderCapture: (evt, gestureState) => false,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) => {
this.setState({
touched: true
});
},
onPanResponderMove: (evt, gestureState) => {
this.setState({
touches: this.state.touches + 1,
});
if (gestureState.moveY > gestureState.y0) {
this.props.showNavBar()
this.setState({
touches: 0
});
}
else {
this.props.hideNavBar()
this.setState({
touches: 0
});
}
},
onPanResponderTerminationRequest: (evt, gestureState) => false,
onPanResponderRelease: (evt, gestureState) => {
if (this.state.touches > 1) {
if (gestureState.moveY > gestureState.y0) {
this.props.showNavBar()
}
else {
this.props.hideNavBar()
}
}
this.setState({
touches: 0
});
},
onPanResponderTerminate: (evt, gestureState) => {
return true;
},
onShouldBlockNativeResponder: (evt, gestureState) => {
return false;
},
});
}
- Use logic based on incoming visible prop in your navBar component and Animated API for height animation.
from react-native-navbar.
Related Issues (20)
- What version of react-native is required? HOT 5
- 1.8.1 is not support in react-native 0.41.2 HOT 2
- Left and Right buttons won't show together HOT 2
- Put image instead of title HOT 6
- iphoneX additional padding? HOT 4
- Drag back handle HOT 6
- header text with icons HOT 6
- App Exits without showing any error HOT 2
- iOS 11 largeTitle
- applying FontFamily to style object giving Error HOT 1
- Disabled option in button configs doesn't work
- remove bottom value for Customtitle style
- Review Pull Requests
- Hiding status bar HOT 1
- KeyboardAvoidingView overlap NavitationBar
- View.propTypes on Android Production causing the app to crash
- Wrapping SafeAreaView creates a white gap between the navbar and status bar HOT 3
- return an error when I import NavigationBar HOT 1
- tried to register two views with the same name GestureHandlerRootView HOT 5
- Add screenshots to examples to make usage clear without cloning/looking at code
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-native-navbar.