-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
React Native collapsible OnDeviceUI navigation #1544
Changes from 6 commits
9cb655a
feb86f3
2c095c2
80b9015
79deb67
f425d2f
d6c2128
bcb4db8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,116 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { View } from 'react-native'; | ||
import React, { Component, PropTypes } from 'react'; | ||
import { Animated, Easing, View, TouchableWithoutFeedback, Image, Text } from 'react-native'; | ||
import style from './style'; | ||
import StoryListView from '../StoryListView'; | ||
import StoryView from '../StoryView'; | ||
|
||
export default function OnDeviceUI(props) { | ||
const { stories, events, url } = props; | ||
export default class OnDeviceUI extends Component { | ||
constructor(props, ...args) { | ||
super(props, ...args); | ||
|
||
return ( | ||
<View style={style.main}> | ||
<View style={style.leftPanel}> | ||
<StoryListView stories={stories} events={events} /> | ||
</View> | ||
<View style={style.rightPanel}> | ||
<View style={style.preview}> | ||
<StoryView url={url} events={events} /> | ||
this.state = { | ||
menuAnimation: new Animated.Value(0), | ||
isMenuOpen: false, | ||
selectedKind: null, | ||
selectedStory: null, | ||
}; | ||
|
||
this.storyChangedHandler = this.handleStoryChanged.bind(this); | ||
this.handleToggleMenu = this.handleToggleMenu.bind(this); | ||
|
||
this.props.events.on('story', this.storyChangedHandler); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.props.events.removeListener('story', this.storyChangedHandler); | ||
} | ||
|
||
handleStoryChanged(storyFn, selection) { | ||
const { kind, story } = selection; | ||
this.setState({ | ||
selectedKind: kind, | ||
selectedStory: story, | ||
}); | ||
} | ||
|
||
handleToggleMenu() { | ||
const isMenuOpen = !this.state.isMenuOpen; | ||
|
||
Animated.timing(this.state.menuAnimation, { | ||
toValue: isMenuOpen ? 1 : 0, | ||
duration: 150, | ||
easing: Easing.linear, | ||
}).start(); | ||
|
||
this.setState({ | ||
isMenuOpen, | ||
}); | ||
} | ||
|
||
render() { | ||
const { stories, events, url } = this.props; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to subscribe for stories being added? Or will added stories become updated in Update: Deferred to #1547 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly not sure. The subscription setup was actually setup by someone else. This PR is just changing the UI to be more giving on space available to the preview section. I can work on cleaning this up in a follow up PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original component received added stories through event emissions -- I think we may want to subscribe to those here too, or otherwise the sidebar may not update as stories become added. cc @shilman or @ndelangen -- do Preview components receive additional stories on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ajwhite right now in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay - sounds like something we can come back to and keep the scope of this PR narrow 👍 Opened #1547, can probably tackle once I'm back in Boston on Tuesday. |
||
const { isMenuOpen, menuAnimation, selectedKind, selectedStory } = this.state; | ||
|
||
const overlayStyles = [style.overlayContainer, { opacity: menuAnimation }]; | ||
|
||
const menuStyles = [ | ||
style.menuContainer, | ||
{ | ||
transform: [ | ||
{ | ||
translateX: menuAnimation.interpolate({ | ||
inputRange: [0, 1], | ||
outputRange: [0, 250], | ||
}), | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
/* eslint-disable global-require */ | ||
const openMenuImage = require('./menu_open.png'); | ||
const closeMenuImage = require('./menu_close.png'); | ||
/* eslint-enable global-require */ | ||
|
||
return ( | ||
<View style={style.main}> | ||
<View style={style.previewContainer}> | ||
<View style={style.headerContainer}> | ||
<TouchableWithoutFeedback onPress={this.handleToggleMenu}> | ||
<View> | ||
<Image source={openMenuImage} style={style.icon} /> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
<Text style={style.headerText} numberOfLines={1}> | ||
{selectedKind} / {selectedStory} | ||
</Text> | ||
</View> | ||
<View style={style.previewWrapper}> | ||
<View style={style.preview}> | ||
<StoryView url={url} events={events} /> | ||
</View> | ||
</View> | ||
</View> | ||
{isMenuOpen && | ||
<TouchableWithoutFeedback onPress={this.handleToggleMenu}> | ||
<Animated.View style={overlayStyles} /> | ||
</TouchableWithoutFeedback>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dropping the trailing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier is not a fan of that. I typically would have it on the next line but prettier complained at me. I'll look at options because I agree that this isn't as readable as it could be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, if prettier did this, then nothing to see here! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved by way of removing this code all together 😄 |
||
<Animated.View style={menuStyles}> | ||
<TouchableWithoutFeedback onPress={this.handleToggleMenu}> | ||
<View style={style.closeButton}> | ||
<Image source={closeMenuImage} style={style.icon} /> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
<StoryListView | ||
stories={stories} | ||
events={events} | ||
selectedKind={selectedKind} | ||
selectedStory={selectedStory} | ||
/> | ||
</Animated.View> | ||
</View> | ||
</View> | ||
); | ||
); | ||
} | ||
} | ||
|
||
OnDeviceUI.propTypes = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,51 @@ import { StyleSheet } from 'react-native'; | |
export default { | ||
main: { | ||
flex: 1, | ||
paddingTop: 20, | ||
backgroundColor: 'rgba(255, 255, 255, 1)', | ||
}, | ||
icon: { | ||
width: 20, | ||
height: 20, | ||
opacity: 0.5, | ||
}, | ||
headerContainer: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
margin: 5, | ||
}, | ||
headerText: { | ||
marginLeft: 5, | ||
fontSize: 14, | ||
color: 'rgba(0, 0, 0, 0.5)', | ||
}, | ||
overlayContainer: { | ||
position: 'absolute', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, you can use StyleSheet.absoluteFillObject like used below in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. I meant to switch them all to be the same but forgot. Will get this updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved. |
||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
backgroundColor: 'rgba(0, 0, 0, 0.6)', | ||
}, | ||
menuContainer: { | ||
position: 'absolute', | ||
top: 0, | ||
bottom: 0, | ||
left: -250, | ||
width: 250, | ||
paddingHorizontal: 8, | ||
paddingTop: 20, | ||
paddingBottom: 8, | ||
backgroundColor: 'rgba(247, 247, 247, 1)', | ||
}, | ||
leftPanel: { | ||
previewContainer: { | ||
flex: 1, | ||
maxWidth: 250, | ||
paddingHorizontal: 8, | ||
paddingBottom: 8, | ||
}, | ||
rightPanel: { | ||
previewWrapper: { | ||
flex: 1, | ||
backgroundColor: 'rgba(255, 255, 255, 1)', | ||
borderWidth: StyleSheet.hairlineWidth, | ||
borderColor: 'rgba(236, 236, 236, 1)', | ||
borderRadius: 4, | ||
marginBottom: 8, | ||
marginHorizontal: 8, | ||
}, | ||
closeButton: { | ||
marginVertical: 5, | ||
}, | ||
preview: { | ||
...StyleSheet.absoluteFillObject, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nitty feedback - but since
props
isn't used, we could just spread all the argumentsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I had props in there before and just forgot to clean this up. I'll get it updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.