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

[AppBar] waterfall behaviour #1321

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
101 changes: 54 additions & 47 deletions docs/src/app/app-routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand All @@ -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} />
Copy link
Member

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

<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} />
Copy link
Member

Choose a reason for hiding this comment

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

All this line changes seem weird. Why do we have those spaces?
Looks like it's for the

    <Route path="/examples">
      <Route path="app-bar-waterfall" component={AppBarWaterfall} />
    </Route>

Is this the right place for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
1 change: 1 addition & 0 deletions docs/src/app/components/AppBar/ExampleIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const AppBarExampleIcon = React.createClass({
return (
<AppBar
title="Title"
position="static"
iconClassNameRight="muidocs-icon-navigation-expand-more"
/>
);
Expand Down
1 change: 1 addition & 0 deletions docs/src/app/components/AppBar/ExampleIconButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const AppBarExampleIconButton = React.createClass({
return (
<AppBar
title={<span style={styles.title} onTouchTap={handleTouchTap}>Title</span>}
position="static"
iconElementLeft={<IconButton><NavigationClose /></IconButton>}
iconElementRight={<FlatButton label="Save" />}
/>
Expand Down
1 change: 1 addition & 0 deletions docs/src/app/components/AppBar/ExampleIconMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const AppBarExampleIconMenu = React.createClass({
return (
<AppBar
title="Title"
position="static"
iconElementLeft={<IconButton><NavigationClose /></IconButton>}
iconElementRight={
<IconMenu
Expand Down
79 changes: 79 additions & 0 deletions docs/src/app/components/examples/app-bar-waterfall-example.jsx
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'}}>
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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;
74 changes: 74 additions & 0 deletions docs/src/app/components/examples/app-bar-waterfall.jsx
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',
Copy link
Member

Choose a reason for hiding this comment

The 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();
Copy link
Member

Choose a reason for hiding this comment

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

For unchanged variable, is better to use const.

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;
Loading