Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2275 from matrix-org/bwindels/scroll-indicators
Browse files Browse the repository at this point in the history
Redesign: add scroll indicator gradients to top and bottom of room sub list
  • Loading branch information
bwindels authored Nov 14, 2018
2 parents b0032b2 + 0f22685 commit 1dad385
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 11 deletions.
28 changes: 20 additions & 8 deletions res/css/structures/_AutoHideScrollbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@ is overflowing. This is what Firefox ends up using. Overflow is detected
in javascript, and adds the mx_AutoHideScrollbar_overflow class to the container.
This only works in Firefox, which should be fine as this fallback is only needed there.
*/
body.mx_scrollbar_nooverlay .mx_AutoHideScrollbar {
overflow-y: hidden;
}
body.mx_scrollbar_nooverlay {
.mx_AutoHideScrollbar {
overflow-y: hidden;
}

body.mx_scrollbar_nooverlay .mx_AutoHideScrollbar:hover {
overflow-y: auto;
}
.mx_AutoHideScrollbar:hover {
overflow-y: auto;
}

/*
offset scrollbar width with negative margin-right
body.mx_scrollbar_nooverlay .mx_AutoHideScrollbar:hover.mx_AutoHideScrollbar_overflow > .mx_AutoHideScrollbar_offset {
margin-right: calc(-1 * var(--scrollbar-width));
include before and after psuedo-elements here so they can
be used to do something interesting like scroll-indicating
gradients (see IndicatorScrollBar)
*/
.mx_AutoHideScrollbar:hover.mx_AutoHideScrollbar_overflow > .mx_AutoHideScrollbar_offset,
.mx_AutoHideScrollbar:hover.mx_AutoHideScrollbar_overflow::before,
.mx_AutoHideScrollbar:hover.mx_AutoHideScrollbar_overflow::after
{
margin-right: calc(-1 * var(--scrollbar-width));
}
}
30 changes: 30 additions & 0 deletions res/css/structures/_RoomSubList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ limitations under the License.
padding: 0 8px;
}

.mx_RoomSubList_scroll.mx_IndicatorScrollbar_topOverflow::before,
.mx_RoomSubList_scroll.mx_IndicatorScrollbar_bottomOverflow::after {
position: sticky;
left: 0;
right: 0;
height: 40px;
content: "";
display: block;
z-index: 100;
pointer-events: none;
}


.mx_RoomSubList_scroll.mx_IndicatorScrollbar_topOverflow > .mx_AutoHideScrollbar_offset {
margin-top: -40px;
}
.mx_RoomSubList_scroll.mx_IndicatorScrollbar_bottomOverflow > .mx_AutoHideScrollbar_offset {
margin-bottom: -40px;
}

.mx_RoomSubList_scroll.mx_IndicatorScrollbar_topOverflow::before {
top: 0;
background: linear-gradient($secondary-accent-color, transparent);
}

.mx_RoomSubList_scroll.mx_IndicatorScrollbar_bottomOverflow::after {
bottom: 0;
background: linear-gradient(transparent, $secondary-accent-color);
}

.collapsed {

.mx_RoomSubList_scroll {
Expand Down
3 changes: 3 additions & 0 deletions src/components/structures/AutoHideScrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default class AutoHideScrollbar extends React.Component {
this.onUnderflow();
}
}
if (this.props.wrappedRef) {
this.props.wrappedRef(ref);
}
}

componentWillUnmount() {
Expand Down
62 changes: 62 additions & 0 deletions src/components/structures/IndicatorScrollbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";
import AutoHideScrollbar from "./AutoHideScrollbar";

export default class IndicatorScrollbar extends React.Component {
constructor(props) {
super(props);
this._collectScroller = this._collectScroller.bind(this);
this.checkOverflow = this.checkOverflow.bind(this);
}

_collectScroller(scroller) {
if (scroller && !this._scroller) {
this._scroller = scroller;
this._scroller.addEventListener("scroll", this.checkOverflow);
this.checkOverflow();
}
}

checkOverflow() {
const hasTopOverflow = this._scroller.scrollTop > 0;
const hasBottomOverflow = this._scroller.scrollHeight >
(this._scroller.scrollTop + this._scroller.clientHeight);
if (hasTopOverflow) {
this._scroller.classList.add("mx_IndicatorScrollbar_topOverflow");
} else {
this._scroller.classList.remove("mx_IndicatorScrollbar_topOverflow");
}
if (hasBottomOverflow) {
this._scroller.classList.add("mx_IndicatorScrollbar_bottomOverflow");
} else {
this._scroller.classList.remove("mx_IndicatorScrollbar_bottomOverflow");
}
}

componentWillUnmount() {
if (this._scroller) {
this._scroller.removeEventListener("scroll", this.checkOverflow);
}
}

render() {
return (<AutoHideScrollbar wrappedRef={this._collectScroller} {... this.props}>
{ this.props.children }
</AutoHideScrollbar>);
}
}
6 changes: 3 additions & 3 deletions src/components/structures/RoomSubList.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import dis from '../../dispatcher';
import Unread from '../../Unread';
import * as RoomNotifs from '../../RoomNotifs';
import * as FormattingUtils from '../../utils/FormattingUtils';
import AutoHideScrollbar from './AutoHideScrollbar';
import IndicatorScrollbar from './IndicatorScrollbar';
import { KeyCode } from '../../Keyboard';
import { Group } from 'matrix-js-sdk';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -333,9 +333,9 @@ const RoomSubList = React.createClass({
tiles.push(...this.props.extraTiles);
return <div style={style} className={subListClasses}>
{this._getHeaderJsx()}
<AutoHideScrollbar className="mx_RoomSubList_scroll">
<IndicatorScrollbar className="mx_RoomSubList_scroll">
{ tiles }
</AutoHideScrollbar>
</IndicatorScrollbar>
</div>;
}
} else {
Expand Down

0 comments on commit 1dad385

Please sign in to comment.