Skip to content

Commit

Permalink
Merge pull request #6 from clmntcrl/header-component
Browse files Browse the repository at this point in the history
Header component
  • Loading branch information
psegalen authored Jun 26, 2018
2 parents 8df9050 + c15da73 commit fb26c4f
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 268 deletions.
12 changes: 6 additions & 6 deletions ios/stdrenegade.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,11 @@
TargetAttributes = {
00E356ED1AD99517003FC87E = {
CreatedOnToolsVersion = 6.2;
DevelopmentTeam = 5T8JDQLB4A;
DevelopmentTeam = W624386YMM;
TestTargetID = 13B07F861A680F5B00A75B9A;
};
13B07F861A680F5B00A75B9A = {
DevelopmentTeam = 5T8JDQLB4A;
DevelopmentTeam = W624386YMM;
};
2D02E47A1E0B4A5D006451C7 = {
CreatedOnToolsVersion = 8.2.1;
Expand Down Expand Up @@ -1323,7 +1323,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 5T8JDQLB4A;
DEVELOPMENT_TEAM = W624386YMM;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand Down Expand Up @@ -1353,7 +1353,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
COPY_PHASE_STRIP = NO;
DEVELOPMENT_TEAM = 5T8JDQLB4A;
DEVELOPMENT_TEAM = W624386YMM;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
Expand All @@ -1380,7 +1380,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = 5T8JDQLB4A;
DEVELOPMENT_TEAM = W624386YMM;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
Expand All @@ -1402,7 +1402,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5T8JDQLB4A;
DEVELOPMENT_TEAM = W624386YMM;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
Expand Down
99 changes: 81 additions & 18 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,86 @@
import React from 'react';
import {View, Image, StyleSheet, Text} from 'react-native';
import React from "react"
import { SafeAreaView, ImageBackground, Animated, Easing, Dimensions, StyleSheet, ViewPropTypes } from "react-native"
import PropTypes from "prop-types"

const Header = () => {
return (
<View>
<Image source={require('../res/images/header-back.jpg')} style={{height:125, width:'100%'}} />
<Image source={require('../res/images/logo.png')} style={styles.positionLogo} />
</View>
)
}
const windowSize = Dimensions.get("window")

class Header extends React.Component {
static propTypes = {
style: ViewPropTypes.style,
scrollContentYOffset: PropTypes.number,
}
static defaultProps = {
scrollContentYOffset: 0,
}
// Header animation configuration
static minHeight = 0
static maxHeight = 80
static deltaAnimationProgressThatDoesNotNeedTiming = 0.5
static computeAnimatedProgressValue = ({ scrollContentYOffset }) =>
scrollContentYOffset >= 0
? Math.max(0, 1 - scrollContentYOffset / (Header.maxHeight - Header.minHeight))
: 1 + (-scrollContentYOffset * 0.3) / (Header.maxHeight - Header.minHeight) // Bounce
static animatedHeight = ({ animatedProgress }) =>
Animated.multiply(animatedProgress, Header.maxHeight - Header.minHeight)
static animatedOpacity = ({ animatedProgress }) => animatedProgress

constructor(props) {
super(props)
this.animatedProgressValue = Header.computeAnimatedProgressValue({
scrollContentYOffset: this.props.scrollContentYOffset,
})
this.animatedProgress = new Animated.Value(this.animatedProgressValue)
}

componentDidUpdate() {
const { scrollContentYOffset } = this.props
const newAnimatedProgressValue = Header.computeAnimatedProgressValue({ scrollContentYOffset })
if (
Math.abs(this.animatedProgressValue - newAnimatedProgressValue) <=
Header.deltaAnimationProgressThatDoesNotNeedTiming
) {
this.animatedProgress.setValue(newAnimatedProgressValue)
} else {
Animated.timing(this.animatedProgress, {
toValue: newAnimatedProgressValue,
duration: 200,
easing: Easing.out(Easing.quad),
}).start()
}
this.animatedProgressValue = newAnimatedProgressValue
}

render() {
return (
<ImageBackground
source={require("../res/images/header-back.jpg")}
style={[this.props.styles, styles.container]}
resizeMode="cover"
>
<SafeAreaView style={{ flex: 1 }}>
<Animated.Image
source={require("../res/images/logo.png")}
style={{
height: Header.animatedHeight({ animatedProgress: this.animatedProgress }),
opacity: Header.animatedOpacity({ animatedProgress: this.animatedProgress }),
}}
resizeMode="contain"
/>
</SafeAreaView>
</ImageBackground>
)
}
}

const styles = StyleSheet.create({
positionLogo: {
width: 80,
height: 80,
position: "absolute",
top: "25%",
left: "40%"
}
});
container: {
position: "absolute",
top: 0,
left: 0,
right: 0,
alignItems: "center",
justifyContent: "center",
},
})

export default Header
42 changes: 42 additions & 0 deletions src/components/ScrollViewWithHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { Component } from "react"
import { SafeAreaView, StyleSheet, ViewPropTypes, ScrollView, View } from "react-native"
import PropTypes from "prop-types"

import Header from "./Header"

export default class ScrollViewWithHeader extends Component {
static propTypes = {
style: ViewPropTypes.style,
children: PropTypes.node,
navigation: PropTypes.object, // Provide navigation object if header is in navigation stack
}

state = {
offsetY: 0,
}

onScroll = ({ nativeEvent }) =>
this.props.navigation
? this.props.navigation.setParams({ scrollContentYOffset: nativeEvent.contentOffset.y })
: this.setState({ offsetY: nativeEvent.contentOffset.y })

render() {
return (
<SafeAreaView style={this.props.style}>
<ScrollView style={{ flex: 1 }} scrollEventThrottle={16} onScroll={this.onScroll}>
<View style={{ flex: 1, marginTop: Header.maxHeight }}>{this.props.children}</View>
</ScrollView>
{!this.props.navigation && <Header style={styles.header} scrollContentYOffset={this.state.offsetY} />}
</SafeAreaView>
)
}
}

const styles = StyleSheet.create({
header: {
position: "absolute",
top: 0,
left: 0,
right: 0,
},
})
12 changes: 3 additions & 9 deletions src/screens/home/Home.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { Component } from "react"
import { StyleSheet, Text, View, Image, Linking, TouchableHighlight } from "react-native"
// React-Native-Elements

// React-Navigation
import { TabNavigator } from "react-navigation"
// Component
import Header from "../../components/Header"
import Agenda from "../../components/Agenda"
import ScrollViewWithHeader from "../../components/ScrollViewWithHeader"

export default class Home extends Component {
openTwitch() {
Expand All @@ -22,8 +17,7 @@ export default class Home extends Component {
}
render() {
return (
<View style={{ flex: 1 }}>
<Header />
<ScrollViewWithHeader style={{ flex: 1 }}>
<View style={styles.containerLive}>
<Text style={styles.live}>Actuellement en live !</Text>
<Text style={styles.emissionLive}>NELIGER!!!!!</Text>
Expand All @@ -35,7 +29,7 @@ export default class Home extends Component {
<Text>Prochainement</Text>
<Agenda />
</View>
</View>
</ScrollViewWithHeader>
)
}
}
Expand Down
134 changes: 61 additions & 73 deletions src/screens/programs/Programs.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,69 @@
import React, { Component } from "react";
import {
StyleSheet,
Text,
View,
Image,
ScrollView,
Button
} from "react-native";
import { StackNavigator } from "react-navigation";
import React, { Component } from "react"
import { StyleSheet, Text, View, Image, ScrollView, Button } from "react-native"

//Component
import Header from "../../components/Header";
import programs from "../../res/data/programs.json";
import { Routes } from ".";
import programs from "../../res/data/programs.json"
import { Routes } from "."

import ScrollViewWithHeader from "../../components/ScrollViewWithHeader"

export default class Programs extends Component {
render() {
return (
<View style={{ justifyContent: "center", alignItems: "center" }}>
<ScrollView style={{ width: "100%" }}>
<View style={{ flex: 1 }}>
{programs.map(program => (
<View key={program.id} style={styles.container}>
<View key={program.id} style={styles.emission}>
<Image
style={styles.logoEmission}
source={{ uri: program.logo }}
/>
<View style={styles.containerDetail}>
<Text style={styles.programName}>{program.name}</Text>
<Button
title="Description"
onPress={() =>
this.props.navigation.navigate(Routes.programsDetails, {
programDetail: program
})
}
/>
</View>
render() {
return (
<ScrollViewWithHeader style={{ flex: 1 }} navigation={this.props.navigation}>
<View style={{ flex: 1 }}>
{programs.map((program) => (
<View key={program.id} style={styles.container}>
<View key={program.id} style={styles.emission}>
<Image style={styles.logoEmission} source={{ uri: program.logo }} />
<View style={styles.containerDetail}>
<Text style={styles.programName}>{program.name}</Text>
<Button
title="Description"
onPress={() =>
this.props.navigation.navigate(Routes.programsDetails, {
programDetail: program,
})
}
/>
</View>
</View>
</View>
))}
</View>
</View>
))}
</View>
</ScrollView>
</View>
);
}
</ScrollViewWithHeader>
)
}
}

const styles = StyleSheet.create({
container: {
backgroundColor: "#DDD",
borderRadius: 80,
marginHorizontal: 20,
marginVertical: 10
},
emission: {
flex: 1,
flexDirection: "row",
height: 80
},
logoEmission: {
borderRadius: 40,
height: 80,
width: 80
},
containerDetail: {
flexDirection: "column",
justifyContent: "space-around",
flex: 1,
height: 60
},
programName: {
flex: 1,
textAlign: "center",
alignItems: "center",
padding: 20,
fontWeight: "500"
}
});
container: {
backgroundColor: "#DDD",
borderRadius: 80,
marginHorizontal: 20,
marginVertical: 10,
},
emission: {
flex: 1,
flexDirection: "row",
height: 80,
},
logoEmission: {
borderRadius: 40,
height: 80,
width: 80,
},
containerDetail: {
flexDirection: "column",
justifyContent: "space-around",
flex: 1,
height: 60,
},
programName: {
flex: 1,
textAlign: "center",
alignItems: "center",
padding: 20,
fontWeight: "500",
},
})
Loading

0 comments on commit fb26c4f

Please sign in to comment.