mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(android): 'isEnabled' now works properly for SegmentedBar (#8711)
This commit is contained in:
@@ -29,7 +29,7 @@ export function pageLoaded(args: EventData) {
|
||||
examples.set("page", "page/main-page");
|
||||
examples.set("perf", "perf/main-page");
|
||||
examples.set("scroll-view", "scroll-view/main-page");
|
||||
examples.set("segStyle", "segmented-bar/all-page");
|
||||
examples.set("segmented-bar", "segmented-bar/main-page");
|
||||
examples.set("search-bar", "search-bar/main-page");
|
||||
examples.set("tab-view", "tab-view/main-page");
|
||||
examples.set("timePicker", "time-picker/time-picker-page");
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import * as frame from "tns-core-modules/ui/frame";
|
||||
|
||||
export function navigate() {
|
||||
frame.topmost().goBack();
|
||||
}
|
||||
10
e2e/ui-tests-app/app/segmented-bar/android-enabled-page.xml
Normal file
10
e2e/ui-tests-app/app/segmented-bar/android-enabled-page.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<Page>
|
||||
<StackLayout>
|
||||
<SegmentedBar selectedIndex="1" isEnabled="false">
|
||||
<SegmentedBarItem title="Item 1" />
|
||||
<SegmentedBarItem title="Item 2" />
|
||||
<SegmentedBarItem title="Item 3" />
|
||||
</SegmentedBar>
|
||||
<Button text="go to previous page" tap="navigate" />
|
||||
</StackLayout>
|
||||
</Page>
|
||||
@@ -1,12 +1,12 @@
|
||||
<Page>
|
||||
<StackLayout>
|
||||
<SegmentedBar selectedIndex="1">
|
||||
<SegmentedBar.items>
|
||||
<SegmentedBarItem title="Item 1" />
|
||||
<SegmentedBarItem title="Item 2" />
|
||||
<SegmentedBarItem title="Item 3" />
|
||||
</SegmentedBar.items>
|
||||
</SegmentedBar>
|
||||
<Button text="go to previous page" tap="navigate"/>
|
||||
</StackLayout>
|
||||
</Page>
|
||||
<StackLayout>
|
||||
<SegmentedBar selectedIndex="1">
|
||||
<SegmentedBar.items>
|
||||
<SegmentedBarItem title="Item 1" />
|
||||
<SegmentedBarItem title="Item 2" />
|
||||
<SegmentedBarItem title="Item 3" />
|
||||
</SegmentedBar.items>
|
||||
</SegmentedBar>
|
||||
<Button text="go to previous page" tap="navigate" />
|
||||
</StackLayout>
|
||||
</Page>
|
||||
19
e2e/ui-tests-app/app/segmented-bar/main-page.ts
Normal file
19
e2e/ui-tests-app/app/segmented-bar/main-page.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { EventData } from "tns-core-modules/data/observable";
|
||||
import { SubMainPageViewModel } from "../sub-main-page-view-model";
|
||||
import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
|
||||
export function pageLoaded(args: EventData) {
|
||||
const page = <Page>args.object;
|
||||
const wrapLayout = <WrapLayout>page.getViewById("wrapLayoutWithExamples");
|
||||
page.bindingContext = new SubMainPageViewModel(wrapLayout, loadExamples());
|
||||
}
|
||||
|
||||
export function loadExamples() {
|
||||
const examples = new Map<string, string>();
|
||||
examples.set("segStyle", "segmented-bar/all-page");
|
||||
examples.set("clean", "segmented-bar/clean-page");
|
||||
examples.set("android-enabled", "segmented-bar/android-enabled-page");
|
||||
|
||||
return examples;
|
||||
}
|
||||
6
e2e/ui-tests-app/app/segmented-bar/main-page.xml
Normal file
6
e2e/ui-tests-app/app/segmented-bar/main-page.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Page loaded="pageLoaded">
|
||||
<ScrollView orientation="vertical" row="1">
|
||||
<WrapLayout id="wrapLayoutWithExamples"/>
|
||||
</ScrollView>
|
||||
</Page>
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Font } from "../styling/font";
|
||||
import {
|
||||
SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsProperty, selectedBackgroundColorProperty,
|
||||
SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsProperty, isEnabledProperty, selectedBackgroundColorProperty,
|
||||
colorProperty, fontInternalProperty, fontSizeProperty, Color, layout
|
||||
} from "./segmented-bar-common";
|
||||
|
||||
@@ -30,6 +30,7 @@ let TabHost: TabHost;
|
||||
let TabChangeListener: TabChangeListener;
|
||||
let TabContentFactory: TabContentFactory;
|
||||
|
||||
// TODO: All TabHost public methods become deprecated in API 30.
|
||||
function initializeNativeClasses(): void {
|
||||
if (TabChangeListener) {
|
||||
return;
|
||||
@@ -238,6 +239,17 @@ export class SegmentedBar extends SegmentedBarBase {
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
public onLoaded() {
|
||||
super.onLoaded();
|
||||
|
||||
// Can only be applied after view is loaded
|
||||
const tabWidget = this.nativeViewProtected.getTabWidget();
|
||||
if (tabWidget)
|
||||
{
|
||||
tabWidget.setEnabled(tabWidget.isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
private insertTab(tabItem: SegmentedBarItem, index: number): void {
|
||||
const tabHost = this.nativeViewProtected;
|
||||
const tab = tabHost.newTabSpec(index + "");
|
||||
@@ -270,4 +282,11 @@ export class SegmentedBar extends SegmentedBarBase {
|
||||
|
||||
selectedIndexProperty.coerce(this);
|
||||
}
|
||||
[isEnabledProperty.setNative](value: boolean) {
|
||||
const tabWidget = this.nativeViewProtected.getTabWidget();
|
||||
if (tabWidget)
|
||||
{
|
||||
tabWidget.setEnabled(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user