-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
[AppBar] waterfall behaviour #1321
Changes from 1 commit
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ import Tabs from './components/pages/components/tabs'; | |
import TextFields from './components/pages/components/text-fields'; | ||
import TimePicker from './components/pages/components/time-picker'; | ||
import Toolbars from './components/pages/components/toolbars'; | ||
import AppBarWaterfall from './components/examples/app-bar-waterfall'; | ||
|
||
|
||
/** | ||
|
@@ -61,57 +62,63 @@ import Toolbars from './components/pages/components/toolbars'; | |
* handler and its parent handler like so: Paper > Components > Master | ||
*/ | ||
const AppRoutes = ( | ||
<Route path="/" component={Master}> | ||
<Route path="home" component={Home} /> | ||
<Redirect from="get-started" to="/get-started/prerequisites" /> | ||
<Route path="get-started" component={GetStarted}> | ||
<Route path="prerequisites" component={Prerequisites} /> | ||
<Route path="installation" component={Installation} /> | ||
<Route path="examples" component={Examples} /> | ||
</Route> | ||
<Route> | ||
<Route path="/" component={Master}> | ||
<Route path="home" component={Home} /> | ||
<Redirect from="get-started" to="/get-started/prerequisites" /> | ||
<Route path="get-started" component={GetStarted}> | ||
<Route path="prerequisites" component={Prerequisites} /> | ||
<Route path="installation" component={Installation} /> | ||
<Route path="examples" component={Examples} /> | ||
</Route> | ||
|
||
<Redirect from="customization" to="/customization/themes" /> | ||
<Route path="customization" component={Customization}> | ||
<Route path="colors" component={Colors} /> | ||
<Route path="themes" component={Themes} /> | ||
<Route path="inline-styles" component={InlineStyles} /> | ||
</Route> | ||
<Redirect from="customization" to="/customization/themes" /> | ||
<Route path="customization" component={Customization}> | ||
<Route path="colors" component={Colors} /> | ||
<Route path="themes" component={Themes} /> | ||
<Route path="inline-styles" component={InlineStyles} /> | ||
</Route> | ||
|
||
<Redirect from="components" to="/components/app-bar" /> | ||
<Route path="components" component={Components}> | ||
<Route path="app-bar" component={AppBar} /> | ||
<Route path="auto-complete" component={AutoComplete} /> | ||
<Route path="avatar" component={Avatar} /> | ||
<Route path="badge" component={Badge} /> | ||
<Route path="buttons" component={Buttons} /> | ||
<Route path="cards" component={Cards} /> | ||
<Route path="date-picker" component={DatePicker} /> | ||
<Route path="dialog" component={Dialog} /> | ||
<Route path="dropdown-menu" component={DropDownMenu} /> | ||
<Route path="grid-list" component={GridList} /> | ||
<Route path="icons" component={Icons} /> | ||
<Route path="icon-buttons" component={IconButtons} /> | ||
<Route path="icon-menus" component={IconMenus} /> | ||
<Route path="left-nav" component={LeftNav} /> | ||
<Route path="lists" component={Lists} /> | ||
<Route path="menus" component={Menus} /> | ||
<Route path="paper" component={Paper} /> | ||
<Route path="popover" component={Popover} /> | ||
<Route path="progress" component={Progress} /> | ||
<Route path="refresh-indicator" component={RefreshIndicator} /> | ||
<Route path="select-fields" component={SelectFields} /> | ||
<Route path="sliders" component={Sliders} /> | ||
<Route path="switches" component={Switches} /> | ||
<Route path="snackbar" component={Snackbar} /> | ||
<Route path="table" component={Table} /> | ||
<Route path="tabs" component={Tabs} /> | ||
<Route path="text-fields" component={TextFields} /> | ||
<Route path="time-picker" component={TimePicker} /> | ||
<Route path="toolbars" component={Toolbars} /> | ||
</Route> | ||
<Redirect from="components" to="/components/appbar" /> | ||
<Route path="components" component={Components}> | ||
<Route path="appbar" component={AppBar} /> | ||
<Route path="auto-complete" component={AutoComplete} /> | ||
<Route path="avatar" component={Avatar} /> | ||
<Route path="badge" component={Badge} /> | ||
<Route path="buttons" component={Buttons} /> | ||
<Route path="cards" component={Cards} /> | ||
<Route path="date-picker" component={DatePicker} /> | ||
<Route path="dialog" component={Dialog} /> | ||
<Route path="dropdown-menu" component={DropDownMenu} /> | ||
<Route path="grid-list" component={GridList} /> | ||
<Route path="icons" component={Icons} /> | ||
<Route path="icon-buttons" component={IconButtons} /> | ||
<Route path="icon-menus" component={IconMenus} /> | ||
<Route path="left-nav" component={LeftNav} /> | ||
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. All this line changes seem weird. Why do we have those spaces?
Is this the right place for it? 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. I really needed that AppBarWaterfall example would not use Master (that has a normal AppBar). Couldn't think of a better solution then. But I just have an idea of a cleaner implementation. I will try it out. 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. I kind of did it, no need for a separate example page. |
||
<Route path="lists" component={Lists} /> | ||
<Route path="menus" component={Menus} /> | ||
<Route path="paper" component={Paper} /> | ||
<Route path="popover" component={Popover} /> | ||
<Route path="progress" component={Progress} /> | ||
<Route path="refresh-indicator" component={RefreshIndicator} /> | ||
<Route path="select-fields" component={SelectFields} /> | ||
<Route path="sliders" component={Sliders} /> | ||
<Route path="switches" component={Switches} /> | ||
<Route path="snackbar" component={Snackbar} /> | ||
<Route path="table" component={Table} /> | ||
<Route path="tabs" component={Tabs} /> | ||
<Route path="text-fields" component={TextFields} /> | ||
<Route path="time-picker" component={TimePicker} /> | ||
<Route path="toolbars" component={Toolbars} /> | ||
</Route> | ||
|
||
<IndexRoute component={Home}/> | ||
<IndexRoute component={Home}/> | ||
</Route> | ||
<Route path="/examples"> | ||
<Route path="app-bar-waterfall" component={AppBarWaterfall} /> | ||
</Route> | ||
</Route> | ||
|
||
); | ||
|
||
export default AppRoutes; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from 'react'; | ||
import {AppBar} from 'material-ui'; | ||
|
||
import IconButton from 'icon-button'; | ||
import MoreVertIcon from 'svg-icons/navigation/more-vert'; | ||
import ArrowBack from 'svg-icons/navigation/arrow-back'; | ||
|
||
const AppBarWaterfallExample = React.createClass({ | ||
|
||
render() { | ||
return ( | ||
<AppBar | ||
position="waterfall" | ||
waterfall={{ | ||
minHeight: 64, | ||
maxHeight: 210, | ||
children: this.getWaterfallChildren(), | ||
onHeightChange: this.onHeightChange, | ||
}} | ||
title={ | ||
<div | ||
ref={el => { this.titleEl = el; }}> | ||
Waterfall AppBar | ||
</div> | ||
} | ||
iconElementLeft={ | ||
<IconButton onClick={this.onBackClick}> | ||
<ArrowBack /> | ||
</IconButton> | ||
} | ||
iconElementRight={ | ||
<IconButton> | ||
<MoreVertIcon/> | ||
</IconButton> | ||
} | ||
/> | ||
); | ||
}, | ||
|
||
getWaterfallChildren() { | ||
let styles = this.getStyles(); | ||
return ( | ||
<div | ||
style={{overflow: 'hidden'}}> | ||
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. place this in the getStyles() too please. |
||
<img | ||
ref={el => { this.logoEl = el; }} | ||
style={styles.logo} | ||
src="images/material-ui-logo.svg"/> | ||
</div> | ||
); | ||
}, | ||
|
||
onHeightChange({height, minHeight, maxHeight}) { | ||
let interpolation = (height - minHeight) / (maxHeight - minHeight); | ||
|
||
// For best performance, we will directly modify style on DOM elements | ||
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. this does improve performance, but leave that to the users, I'd say lets just go with re-render here for brevity. Do you agree @oliviertassinari ? 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. I needed this type of optimization for mobile version. But I will modify the example to add also the simple, un-optimized version, that just use setState and re-renders. 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. yeah, providing the both ways to do it seems like a good idea 👍 Thanks |
||
this.logoEl.style.transform = `translate3d(80px,0,0) scale3d(${interpolation}, ${interpolation}, 1)`; | ||
this.logoEl.style.opacity = interpolation; | ||
this.titleEl.style.opacity = 1 - interpolation; | ||
}, | ||
|
||
onBackClick() { | ||
window.history.back(); | ||
}, | ||
|
||
getStyles() { | ||
return { | ||
logo: { | ||
height: 120, | ||
margin: '0 auto', | ||
display: 'block', | ||
transformOrigin: '25% 100% 0', | ||
transform: 'translate3d(80px,0,0)', | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
export default AppBarWaterfallExample; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import {AppCanvas, Styles, Mixins} from 'material-ui'; | ||
|
||
import CodeExample from '../code-example/code-example'; | ||
import FullWidthSection from '../full-width-section'; | ||
|
||
import AppBarWaterfallExample from './app-bar-waterfall-example'; | ||
import AppBarWaterfallExampleCode from '!raw!./app-bar-waterfall-example'; | ||
|
||
const {StylePropable} = Mixins; | ||
const {Typography} = Styles; | ||
const ThemeManager = Styles.ThemeManager; | ||
const DefaultRawTheme = Styles.LightRawTheme; | ||
|
||
const AppBarWaterfall = React.createClass({ | ||
|
||
mixins: [StylePropable], | ||
|
||
getInitialState() { | ||
let muiTheme = ThemeManager.getMuiTheme(DefaultRawTheme); | ||
// To switch to RTL... | ||
// muiTheme.isRtl = true; | ||
return { | ||
muiTheme, | ||
}; | ||
}, | ||
|
||
contextTypes: { | ||
router: React.PropTypes.func, | ||
}, | ||
|
||
childContextTypes: { | ||
muiTheme: React.PropTypes.object, | ||
}, | ||
|
||
getChildContext() { | ||
return { | ||
muiTheme: this.state.muiTheme, | ||
}; | ||
}, | ||
|
||
getStyles() { | ||
return { | ||
headline: { | ||
//headline | ||
fontSize: '24px', | ||
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. px unit is not needed for all the properties. For instance, this one |
||
lineHeight: '32px', | ||
paddingTop: '16px', | ||
marginBottom: '12px', | ||
letterSpacing: '0', | ||
fontWeight: Typography.fontWeightNormal, | ||
color: Typography.textDarkBlack, | ||
}, | ||
}; | ||
}, | ||
|
||
render() { | ||
let styles = this.getStyles(); | ||
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 unchanged variable, is better to use |
||
return ( | ||
<AppCanvas> | ||
<AppBarWaterfallExample/> | ||
<FullWidthSection> | ||
<h2 style={styles.headline}>Waterfall AppBar</h2> | ||
|
||
<p>Here is an example of how you can obtain a nice animation effect on scroll | ||
when using position waterfall.</p> | ||
<CodeExample code={AppBarWaterfallExampleCode}/> | ||
</FullWidthSection> | ||
</AppCanvas> | ||
); | ||
}, | ||
}); | ||
|
||
export default AppBarWaterfall; |
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.
please change this back to app-bar, this breaks navigation in the components section