mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-31 17:53:50 +00:00
[fix] ScrollView support for hiding scroll indicators
Implements 'showsHorizontalScrollIndicator' and 'showVerticalScrollIndicator' by polyfilling the 'scrollbar-width' property from the draft CSS spec for scrollbars. Scrollbars can only be shown for both or neither axis. Close #1307 Co-authored-by: Nicolas Gallagher <nicolasgallagher@gmail.com>
This commit is contained in:
committed by
Nicolas Gallagher
parent
be5106f5d3
commit
fa09df8b59
@@ -122,6 +122,8 @@ export default class ScrollViewBase extends Component<*> {
|
|||||||
...other
|
...other
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const hideScrollbar =
|
||||||
|
showsHorizontalScrollIndicator === false || showsVerticalScrollIndicator === false;
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
{...other}
|
{...other}
|
||||||
@@ -129,10 +131,11 @@ export default class ScrollViewBase extends Component<*> {
|
|||||||
onTouchMove={this._createPreventableScrollHandler(this.props.onTouchMove)}
|
onTouchMove={this._createPreventableScrollHandler(this.props.onTouchMove)}
|
||||||
onWheel={this._createPreventableScrollHandler(this.props.onWheel)}
|
onWheel={this._createPreventableScrollHandler(this.props.onWheel)}
|
||||||
ref={this._setViewRef}
|
ref={this._setViewRef}
|
||||||
style={StyleSheet.compose(
|
style={[
|
||||||
style,
|
style,
|
||||||
!scrollEnabled && styles.scrollDisabled
|
!scrollEnabled && styles.scrollDisabled,
|
||||||
)}
|
hideScrollbar && style.hideScrollbar
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -204,5 +207,8 @@ export default class ScrollViewBase extends Component<*> {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
scrollDisabled: {
|
scrollDisabled: {
|
||||||
touchAction: 'none'
|
touchAction: 'none'
|
||||||
|
},
|
||||||
|
hideScrollbar: {
|
||||||
|
scrollbarWidth: 'none'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+9
@@ -58,6 +58,15 @@ Object {
|
|||||||
],
|
],
|
||||||
"value": "box-only",
|
"value": "box-only",
|
||||||
},
|
},
|
||||||
|
"r-scrollbarWidth-2eszeu": Object {
|
||||||
|
"identifier": "r-scrollbarWidth-2eszeu",
|
||||||
|
"property": "scrollbarWidth",
|
||||||
|
"rules": Array [
|
||||||
|
".r-scrollbarWidth-2eszeu::-webkit-scrollbar{display:none}",
|
||||||
|
".r-scrollbarWidth-2eszeu{overflow:-moz-scrollbars-none;-ms-overflow-style:none}",
|
||||||
|
],
|
||||||
|
"value": "none",
|
||||||
|
},
|
||||||
"r-transform-1ehiua4": Object {
|
"r-transform-1ehiua4": Object {
|
||||||
"identifier": "r-transform-1ehiua4",
|
"identifier": "r-transform-1ehiua4",
|
||||||
"property": "transform",
|
"property": "transform",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ describe('StyleSheet/compile', () => {
|
|||||||
fontFamily: 'System',
|
fontFamily: 'System',
|
||||||
marginHorizontal: 10,
|
marginHorizontal: 10,
|
||||||
placeholderTextColor: 'gray',
|
placeholderTextColor: 'gray',
|
||||||
|
scrollbarWidth: 'none',
|
||||||
pointerEvents: 'box-only',
|
pointerEvents: 'box-only',
|
||||||
transform: [
|
transform: [
|
||||||
{
|
{
|
||||||
|
|||||||
+14
-2
@@ -75,7 +75,7 @@ export function atomic(style: Style): CompilerOutput {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile simple style object to classic CSS rules.
|
* Compile simple style object to classic CSS rules.
|
||||||
* No support for 'placeholderTextColor' or 'pointerEvents'.
|
* No support for 'placeholderTextColor', 'scrollbarWidth', or 'pointerEvents'.
|
||||||
*/
|
*/
|
||||||
export function classic(style: Style, name: string): CompilerOutput {
|
export function classic(style: Style, name: string): CompilerOutput {
|
||||||
const identifier = createIdentifier('css', name, style);
|
const identifier = createIdentifier('css', name, style);
|
||||||
@@ -97,7 +97,7 @@ export function classic(style: Style, name: string): CompilerOutput {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile simple style object to inline DOM styles.
|
* Compile simple style object to inline DOM styles.
|
||||||
* No support for 'animationKeyframes', 'placeholderTextColor', or 'pointerEvents'.
|
* No support for 'animationKeyframes', 'placeholderTextColor', 'scrollbarWidth', or 'pointerEvents'.
|
||||||
*/
|
*/
|
||||||
export function inline(style: Style) {
|
export function inline(style: Style) {
|
||||||
return prefixInlineStyles(createReactDOMStyle(style));
|
return prefixInlineStyles(createReactDOMStyle(style));
|
||||||
@@ -144,6 +144,18 @@ function createAtomicRules(identifier: string, property, value): Rules {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Polyfill for draft spec
|
||||||
|
// https://drafts.csswg.org/css-scrollbars-1/
|
||||||
|
case 'scrollbarWidth': {
|
||||||
|
if (value === 'none') {
|
||||||
|
rules.push(
|
||||||
|
`${selector}::-webkit-scrollbar{display:none}`,
|
||||||
|
`${selector}{overflow:-moz-scrollbars-none;-ms-overflow-style:none}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// See #513
|
// See #513
|
||||||
case 'pointerEvents': {
|
case 'pointerEvents': {
|
||||||
let finalValue = value;
|
let finalValue = value;
|
||||||
|
|||||||
@@ -231,9 +231,10 @@ export default function createStyleResolver() {
|
|||||||
// require more complex transforms into multiple CSS rules. Here we assume that StyleManager
|
// require more complex transforms into multiple CSS rules. Here we assume that StyleManager
|
||||||
// can bind these styles to a className, and prevent them becoming invalid inline-styles.
|
// can bind these styles to a className, and prevent them becoming invalid inline-styles.
|
||||||
if (
|
if (
|
||||||
styleProp === 'pointerEvents' ||
|
styleProp === 'animationKeyframes' ||
|
||||||
styleProp === 'placeholderTextColor' ||
|
styleProp === 'placeholderTextColor' ||
|
||||||
styleProp === 'animationKeyframes'
|
styleProp === 'pointerEvents' ||
|
||||||
|
styleProp === 'scrollbarWidth'
|
||||||
) {
|
) {
|
||||||
const a = atomic({ [styleProp]: value });
|
const a = atomic({ [styleProp]: value });
|
||||||
Object.values(a).forEach(({ identifier, rules }) => {
|
Object.values(a).forEach(({ identifier, rules }) => {
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ const ViewStylePropTypes = {
|
|||||||
overscrollBehavior: overscrollBehaviorType,
|
overscrollBehavior: overscrollBehaviorType,
|
||||||
overscrollBehaviorX: overscrollBehaviorType,
|
overscrollBehaviorX: overscrollBehaviorType,
|
||||||
overscrollBehaviorY: overscrollBehaviorType,
|
overscrollBehaviorY: overscrollBehaviorType,
|
||||||
|
scrollbarWidth: oneOf(['auto', 'none']),
|
||||||
scrollSnapAlign: string,
|
scrollSnapAlign: string,
|
||||||
scrollSnapType: string,
|
scrollSnapType: string,
|
||||||
WebkitMaskImage: string,
|
WebkitMaskImage: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user