mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
feat(scrollbar): add isScrollEnabled property (#6640)
This commit is contained in:
@ -31,7 +31,6 @@ const androidBackPressedEvent = "androidBackPressed";
|
||||
const modalMap = new Map<number, DialogOptions>();
|
||||
|
||||
let TouchListener: TouchListener;
|
||||
let disableUserInteractionListener: org.nativescript.widgets.DisableUserInteractionListener;
|
||||
let DialogFragment: DialogFragment;
|
||||
|
||||
interface DialogOptions {
|
||||
@ -50,14 +49,6 @@ interface DialogFragment {
|
||||
new(): android.support.v4.app.DialogFragment;
|
||||
}
|
||||
|
||||
function initializeDisabledListener(): void {
|
||||
if (disableUserInteractionListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
disableUserInteractionListener = new org.nativescript.widgets.DisableUserInteractionListener();
|
||||
}
|
||||
|
||||
function initializeTouchListener(): void {
|
||||
if (TouchListener) {
|
||||
return;
|
||||
@ -649,9 +640,8 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[isUserInteractionEnabledProperty.setNative](value: boolean) {
|
||||
if (this.nativeViewProtected.setClickable) {
|
||||
this.nativeViewProtected.setClickable(value);
|
||||
}
|
||||
this.nativeViewProtected.setClickable(value);
|
||||
this.nativeViewProtected.setFocusable(value);
|
||||
}
|
||||
|
||||
[visibilityProperty.getDefault](): Visibility {
|
||||
|
@ -11,6 +11,7 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
|
||||
|
||||
public orientation: Orientation;
|
||||
public scrollBarIndicatorVisible: boolean;
|
||||
public isScrollEnabled: boolean;
|
||||
|
||||
public addEventListener(arg: string, callback: any, thisArg?: any) {
|
||||
super.addEventListener(arg, callback, thisArg);
|
||||
@ -102,4 +103,10 @@ export const scrollBarIndicatorVisibleProperty = new Property<ScrollViewBase, bo
|
||||
name: "scrollBarIndicatorVisible", defaultValue: true,
|
||||
valueConverter: booleanConverter
|
||||
});
|
||||
scrollBarIndicatorVisibleProperty.register(ScrollViewBase);
|
||||
scrollBarIndicatorVisibleProperty.register(ScrollViewBase);
|
||||
|
||||
export const isScrollEnabledProperty = new Property<ScrollViewBase, boolean>({
|
||||
name: "isScrollEnabled", defaultValue: true,
|
||||
valueConverter: booleanConverter
|
||||
});
|
||||
isScrollEnabledProperty.register(ScrollViewBase);
|
@ -1,5 +1,8 @@
|
||||
import { ScrollEventData } from ".";
|
||||
import { ScrollViewBase, layout, scrollBarIndicatorVisibleProperty } from "./scroll-view-common";
|
||||
import {
|
||||
ScrollViewBase, layout, scrollBarIndicatorVisibleProperty,
|
||||
isUserInteractionEnabledProperty, isScrollEnabledProperty
|
||||
} from "./scroll-view-common";
|
||||
|
||||
export * from "./scroll-view-common";
|
||||
|
||||
@ -44,6 +47,21 @@ export class ScrollView extends ScrollViewBase {
|
||||
return nativeView.getScrollableLength() / layout.getDisplayDensity();
|
||||
}
|
||||
|
||||
[isUserInteractionEnabledProperty.setNative](value: boolean) {
|
||||
// NOTE: different behavior on iOS & Android:
|
||||
// iOS disables user interaction recursively for all subviews as well
|
||||
this.nativeViewProtected.setClickable(value);
|
||||
this.nativeViewProtected.setFocusable(value);
|
||||
this.nativeViewProtected.setScrollEnabled(value);
|
||||
}
|
||||
|
||||
[isScrollEnabledProperty.getDefault](): boolean {
|
||||
return this.nativeViewProtected.getScrollEnabled();
|
||||
}
|
||||
[isScrollEnabledProperty.setNative](value: boolean) {
|
||||
this.nativeViewProtected.setScrollEnabled(value);
|
||||
}
|
||||
|
||||
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
|
||||
return true;
|
||||
}
|
||||
@ -57,7 +75,7 @@ export class ScrollView extends ScrollViewBase {
|
||||
|
||||
public scrollToVerticalOffset(value: number, animated: boolean) {
|
||||
const nativeView = this.nativeViewProtected;
|
||||
if (nativeView && this.orientation === "vertical") {
|
||||
if (nativeView && this.orientation === "vertical" && this.isScrollEnabled) {
|
||||
value *= layout.getDisplayDensity();
|
||||
|
||||
if (animated) {
|
||||
@ -70,7 +88,7 @@ export class ScrollView extends ScrollViewBase {
|
||||
|
||||
public scrollToHorizontalOffset(value: number, animated: boolean) {
|
||||
const nativeView = this.nativeViewProtected;
|
||||
if (nativeView && this.orientation === "horizontal") {
|
||||
if (nativeView && this.orientation === "horizontal" && this.isScrollEnabled) {
|
||||
value *= layout.getDisplayDensity();
|
||||
|
||||
if (animated) {
|
||||
|
@ -14,6 +14,11 @@ export class ScrollView extends ContentView {
|
||||
*/
|
||||
public static scrollEvent: string;
|
||||
|
||||
/**
|
||||
* Gets or sets a value indicating whether scroll is enabled.
|
||||
*/
|
||||
isScrollEnabled: boolean;
|
||||
|
||||
/**
|
||||
* Gets a value that contains the vertical offset of the scrolled content.
|
||||
*/
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { ScrollEventData } from ".";
|
||||
import { View, layout, ScrollViewBase, scrollBarIndicatorVisibleProperty } from "./scroll-view-common";
|
||||
import {
|
||||
View, layout, ScrollViewBase, scrollBarIndicatorVisibleProperty, isScrollEnabledProperty
|
||||
} from "./scroll-view-common";
|
||||
import { ios as iosUtils } from "../../utils/utils";
|
||||
// HACK: Webpack. Use a fully-qualified import to allow resolve.extensions(.ios.js) to
|
||||
// kick in. `../utils` doesn't seem to trigger the webpack extensions mechanism.
|
||||
@ -99,6 +101,13 @@ export class ScrollView extends ScrollViewBase {
|
||||
return Math.max(0, this.nativeViewProtected.contentSize.height - this.nativeViewProtected.bounds.size.height);
|
||||
}
|
||||
|
||||
[isScrollEnabledProperty.getDefault](): boolean {
|
||||
return this.nativeViewProtected.scrollEnabled;
|
||||
}
|
||||
[isScrollEnabledProperty.setNative](value: boolean) {
|
||||
this.nativeViewProtected.scrollEnabled = value;
|
||||
}
|
||||
|
||||
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
|
||||
return true;
|
||||
}
|
||||
@ -107,14 +116,14 @@ export class ScrollView extends ScrollViewBase {
|
||||
}
|
||||
|
||||
public scrollToVerticalOffset(value: number, animated: boolean) {
|
||||
if (this.nativeViewProtected && this.orientation === "vertical") {
|
||||
if (this.nativeViewProtected && this.orientation === "vertical" && this.isScrollEnabled) {
|
||||
const bounds = this.nativeViewProtected.bounds.size;
|
||||
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated);
|
||||
}
|
||||
}
|
||||
|
||||
public scrollToHorizontalOffset(value: number, animated: boolean) {
|
||||
if (this.nativeViewProtected && this.orientation === "horizontal") {
|
||||
if (this.nativeViewProtected && this.orientation === "horizontal" && this.isScrollEnabled) {
|
||||
const bounds = this.nativeViewProtected.bounds.size;
|
||||
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated);
|
||||
}
|
||||
|
@ -342,11 +342,15 @@
|
||||
export class VerticalScrollView extends android.widget.ScrollView {
|
||||
constructor(context: android.content.Context);
|
||||
public getScrollableLength(): number;
|
||||
public getScrollEnabled(): boolean;
|
||||
public setScrollEnabled(value: boolean): void;
|
||||
}
|
||||
|
||||
export class HorizontalScrollView extends android.widget.HorizontalScrollView {
|
||||
constructor(context: android.content.Context);
|
||||
public getScrollableLength(): number;
|
||||
public getScrollEnabled(): boolean;
|
||||
public setScrollEnabled(value: boolean): void;
|
||||
}
|
||||
|
||||
export class ImageView extends android.widget.ImageView {
|
||||
|
Reference in New Issue
Block a user