Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full screen experience - Content scroll underneath transparent status bar #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions js/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
View,
StatusBar,
StyleSheet,
Platform,
AppState,
} from 'react-native';

Expand Down Expand Up @@ -121,7 +120,7 @@ export class App extends Component {
<View style={styles.container}>
<StatusBar
translucent={true}
backgroundColor="rgba(0, 0, 0, 0.2)"
backgroundColor="transparent"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep a bit of background color so that if status-bar icons are over a white background (in our app) they are still visible?

barStyle="light-content"
/>
<Navigator
Expand All @@ -136,9 +135,10 @@ export class App extends Component {
renderScene({ id, data }, navigator) {
switch (id) {
case 'item': return <Item itemId={data.itemId} navigator={navigator}/>;
default:
var Component = this.routes[id].component;
default: {
Copy link
Member

@arcturus arcturus Jan 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the curly brackets needed? I'm just curious.

Copy link
Contributor Author

@gmarty gmarty Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's to create a new scope to allow the use of const.

const Component = this.routes[id].component;
return <Component navigator={navigator}/>;
}
}
}
}
Expand All @@ -155,7 +155,6 @@ const styles = StyleSheet.create({

scene: {
backgroundColor: '#333',
paddingTop: Platform.OS === 'ios' ? 20 : 24,
},
});

Expand Down
6 changes: 5 additions & 1 deletion js/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
Text,
StyleSheet,
TouchableOpacity,
Platform,
StatusBar,
} from 'react-native';

export default class Header extends Component {
Expand Down Expand Up @@ -81,11 +83,13 @@ Header.propTypes = {
navigator: PropTypes.object,
};

Header.HEIGHT = 54;
Header.STATUS_BAR_HEIGHT = Platform.OS === 'ios' ? 20 : StatusBar.currentHeight;
Header.HEIGHT = 54 + Header.STATUS_BAR_HEIGHT;

const styles = StyleSheet.create({
header: {
backgroundColor: '#333',
paddingTop: Header.STATUS_BAR_HEIGHT,
height: Header.HEIGHT,
flexDirection: 'row',
alignItems: 'center',
Expand Down
3 changes: 1 addition & 2 deletions js/components/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ const styles = StyleSheet.create({

image: {
flex: 1,
paddingVertical: 10,
paddingHorizontal: 12,
padding: 12,
width: null,
height: null,
resizeMode: 'cover',
Expand Down
33 changes: 27 additions & 6 deletions js/scenes/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Home extends Component {
// never bind functions in render(), it
// messes with react's diffing logic
this.onSettingsPress = this.onSettingsPress.bind(this);
this.renderHeader = this.renderHeader.bind(this);
this.renderRow = this.renderRow.bind(this);
this.onPanEnd = this.onPanEnd.bind(this);
this.onScroll = this.onScroll.bind(this);
Expand All @@ -46,20 +47,20 @@ export class Home extends Component {
// create a clamped property that we can
// use for translating the list view
this.translateY = this.state.listY.interpolate({
inputRange: [0, Header.HEIGHT],
outputRange: [0, Header.HEIGHT],
inputRange: [0, Header.HEIGHT - Header.STATUS_BAR_HEIGHT],
outputRange: [0, Header.HEIGHT - Header.STATUS_BAR_HEIGHT],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this calculation once?

const MAX_Y = Header.HEIGHT - Header.STATUS_BAR_HEIGHT;

extrapolate: 'clamp',
});

// fades the header in/out in sync with list position
this.opacity = this.translateY.interpolate({
inputRange: [0, Header.HEIGHT],
inputRange: [0, Header.HEIGHT - Header.STATUS_BAR_HEIGHT],
outputRange: [0, 1],
});

// scales the header in/out in sync with list position
this.scale = this.translateY.interpolate({
inputRange: [0, Header.HEIGHT],
inputRange: [0, Header.HEIGHT - Header.STATUS_BAR_HEIGHT],
outputRange: [0.95, 1],
});

Expand Down Expand Up @@ -364,7 +365,10 @@ export class Home extends Component {
* @param {Number} y
*/
clamp(y) {
if (y > Header.HEIGHT) return { value: Header.HEIGHT, offset: y - Header.HEIGHT };
if (y > Header.HEIGHT) return {
value: Header.HEIGHT,
offset: y - Header.HEIGHT,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really funky syntax, can you find an alternative :-/

else if (y < 0) return { value: 0, offset: y };
else return { value: y, offset: 0 };
}
Expand All @@ -391,7 +395,8 @@ export class Home extends Component {
title="Home"
action="Settings"
navigator={this.navigator}
onActionPress={this.onSettingsPress}/>
onActionPress={this.onSettingsPress}
style={styles.header}/>
</Animated.View>

<Animated.View
Expand Down Expand Up @@ -427,6 +432,7 @@ export class Home extends Component {
<ListView
ref="list"
dataSource={this.dataSource}
renderHeader={this.renderHeader}
renderRow={this.renderRow}
onScroll={this.onScroll}
scrollEventThrottle={16}
Expand All @@ -436,6 +442,12 @@ export class Home extends Component {
);
}

renderHeader() {
return (
<View style={styles.firstRow}/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This element overhangs the header content and blocks the header buttons. 'Settings' button is difficult to press.

);
}

renderRow({ value: { id, imageUri, createdByUser, timeCreated } }) {
const publisherImageUri = createdByUser.imageUri;
const publisherName = createdByUser.name;
Expand Down Expand Up @@ -483,6 +495,15 @@ const styles = StyleSheet.create({
flex: 1,
},

firstRow: {
height: Header.STATUS_BAR_HEIGHT,
},

header: {
height: 54,
marginTop: Header.STATUS_BAR_HEIGHT / 2,
},

listContainer: {
flex: 1,
position: 'absolute',
Expand Down