FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(scrollbar): add isScrollEnabled property (#6640) · NativeScript/NativeScript@ae0fa90 · GitHub

Commit ae0fa90

Browse files
authored
feat(scrollbar): add isScrollEnabled property (#6640)
1 parent 64bccb9 commit ae0fa90

6 files changed

Lines changed: 52 additions & 19 deletions

File tree

‎tns-core-modules/ui/core/view/view.android.ts‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const androidBackPressedEvent = "androidBackPressed";
3131
const modalMap = new Map<number, DialogOptions>();
3232

3333
let TouchListener: TouchListener;
34-
let disableUserInteractionListener: org.nativescript.widgets.DisableUserInteractionListener;
3534
let DialogFragment: DialogFragment;
3635

3736
interface DialogOptions {
@@ -50,14 +49,6 @@ interface DialogFragment {
5049
new(): android.support.v4.app.DialogFragment;
5150
}
5251

53-
function initializeDisabledListener(): void {
54-
if (disableUserInteractionListener) {
55-
return;
56-
}
57-
58-
disableUserInteractionListener = new org.nativescript.widgets.DisableUserInteractionListener();
59-
}
60-
6152
function initializeTouchListener(): void {
6253
if (TouchListener) {
6354
return;
@@ -649,9 +640,8 @@ export class View extends ViewCommon {
649640
}
650641

651642
[isUserInteractionEnabledProperty.setNative](value: boolean) {
652-
if (this.nativeViewProtected.setClickable) {
653-
this.nativeViewProtected.setClickable(value);
654-
}
643+
this.nativeViewProtected.setClickable(value);
644+
this.nativeViewProtected.setFocusable(value);
655645
}
656646

657647
[visibilityProperty.getDefault](): Visibility {

‎tns-core-modules/ui/scroll-view/scroll-view-common.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
1111

1212
public orientation: Orientation;
1313
public scrollBarIndicatorVisible: boolean;
14+
public isScrollEnabled: boolean;
1415

1516
public addEventListener(arg: string, callback: any, thisArg?: any) {
1617
super.addEventListener(arg, callback, thisArg);
@@ -102,4 +103,10 @@ export const scrollBarIndicatorVisibleProperty = new Property<ScrollViewBase, bo
102103
name: "scrollBarIndicatorVisible", defaultValue: true,
103104
valueConverter: booleanConverter
104105
});
105-
scrollBarIndicatorVisibleProperty.register(ScrollViewBase);
106+
scrollBarIndicatorVisibleProperty.register(ScrollViewBase);
107+
108+
export const isScrollEnabledProperty = new Property<ScrollViewBase, boolean>({
109+
name: "isScrollEnabled", defaultValue: true,
110+
valueConverter: booleanConverter
111+
});
112+
isScrollEnabledProperty.register(ScrollViewBase);

‎tns-core-modules/ui/scroll-view/scroll-view.android.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ScrollEventData } from ".";
2-
import { ScrollViewBase, layout, scrollBarIndicatorVisibleProperty } from "./scroll-view-common";
2+
import {
3+
ScrollViewBase, layout, scrollBarIndicatorVisibleProperty,
4+
isUserInteractionEnabledProperty, isScrollEnabledProperty
5+
} from "./scroll-view-common";
36

47
export * from "./scroll-view-common";
58

@@ -44,6 +47,21 @@ export class ScrollView extends ScrollViewBase {
4447
return nativeView.getScrollableLength() / layout.getDisplayDensity();
4548
}
4649

50+
[isUserInteractionEnabledProperty.setNative](value: boolean) {
51+
// NOTE: different behavior on iOS & Android:
52+
// iOS disables user interaction recursively for all subviews as well
53+
this.nativeViewProtected.setClickable(value);
54+
this.nativeViewProtected.setFocusable(value);
55+
this.nativeViewProtected.setScrollEnabled(value);
56+
}
57+
58+
[isScrollEnabledProperty.getDefault](): boolean {
59+
return this.nativeViewProtected.getScrollEnabled();
60+
}
61+
[isScrollEnabledProperty.setNative](value: boolean) {
62+
this.nativeViewProtected.setScrollEnabled(value);
63+
}
64+
4765
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
4866
return true;
4967
}
@@ -57,7 +75,7 @@ export class ScrollView extends ScrollViewBase {
5775

5876
public scrollToVerticalOffset(value: number, animated: boolean) {
5977
const nativeView = this.nativeViewProtected;
60-
if (nativeView && this.orientation === "vertical") {
78+
if (nativeView && this.orientation === "vertical" && this.isScrollEnabled) {
6179
value *= layout.getDisplayDensity();
6280

6381
if (animated) {
@@ -70,7 +88,7 @@ export class ScrollView extends ScrollViewBase {
7088

7189
public scrollToHorizontalOffset(value: number, animated: boolean) {
7290
const nativeView = this.nativeViewProtected;
73-
if (nativeView && this.orientation === "horizontal") {
91+
if (nativeView && this.orientation === "horizontal" && this.isScrollEnabled) {
7492
value *= layout.getDisplayDensity();
7593

7694
if (animated) {

‎tns-core-modules/ui/scroll-view/scroll-view.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export class ScrollView extends ContentView {
1414
*/
1515
public static scrollEvent: string;
1616

17+
/**
18+
* Gets or sets a value indicating whether scroll is enabled.
19+
*/
20+
isScrollEnabled: boolean;
21+
1722
/**
1823
* Gets a value that contains the vertical offset of the scrolled content.
1924
*/

‎tns-core-modules/ui/scroll-view/scroll-view.ios.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ScrollEventData } from ".";
2-
import { View, layout, ScrollViewBase, scrollBarIndicatorVisibleProperty } from "./scroll-view-common";
2+
import {
3+
View, layout, ScrollViewBase, scrollBarIndicatorVisibleProperty, isScrollEnabledProperty
4+
} from "./scroll-view-common";
35
import { ios as iosUtils } from "../../utils/utils";
46
// HACK: Webpack. Use a fully-qualified import to allow resolve.extensions(.ios.js) to
57
// kick in. `../utils` doesn't seem to trigger the webpack extensions mechanism.
@@ -99,6 +101,13 @@ export class ScrollView extends ScrollViewBase {
99101
return Math.max(0, this.nativeViewProtected.contentSize.height - this.nativeViewProtected.bounds.size.height);
100102
}
101103

104+
[isScrollEnabledProperty.getDefault](): boolean {
105+
return this.nativeViewProtected.scrollEnabled;
106+
}
107+
[isScrollEnabledProperty.setNative](value: boolean) {
108+
this.nativeViewProtected.scrollEnabled = value;
109+
}
110+
102111
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
103112
return true;
104113
}
@@ -107,14 +116,14 @@ export class ScrollView extends ScrollViewBase {
107116
}
108117

109118
public scrollToVerticalOffset(value: number, animated: boolean) {
110-
if (this.nativeViewProtected && this.orientation === "vertical") {
119+
if (this.nativeViewProtected && this.orientation === "vertical" && this.isScrollEnabled) {
111120
const bounds = this.nativeViewProtected.bounds.size;
112121
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated);
113122
}
114123
}
115124

116125
public scrollToHorizontalOffset(value: number, animated: boolean) {
117-
if (this.nativeViewProtected && this.orientation === "horizontal") {
126+
if (this.nativeViewProtected && this.orientation === "horizontal" && this.isScrollEnabled) {
118127
const bounds = this.nativeViewProtected.bounds.size;
119128
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated);
120129
}

‎tns-platform-declarations/android/org.nativescript.widgets.d.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,15 @@
342342
export class VerticalScrollView extends android.widget.ScrollView {
343343
constructor(context: android.content.Context);
344344
public getScrollableLength(): number;
345+
public getScrollEnabled(): boolean;
346+
public setScrollEnabled(value: boolean): void;
345347
}
346348

347349
export class HorizontalScrollView extends android.widget.HorizontalScrollView {
348350
constructor(context: android.content.Context);
349351
public getScrollableLength(): number;
352+
public getScrollEnabled(): boolean;
353+
public setScrollEnabled(value: boolean): void;
350354
}
351355

352356
export class ImageView extends android.widget.ImageView {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL