fix(android): 'isEnabled' now works properly for SegmentedBar (#8711)

This commit is contained in:
DimitrisRK
2020-07-22 23:46:05 +03:00
committed by GitHub
parent 979130de31
commit 08502527eb
7 changed files with 72 additions and 13 deletions

View File

@@ -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");

View File

@@ -0,0 +1,5 @@
import * as frame from "tns-core-modules/ui/frame";
export function navigate() {
frame.topmost().goBack();
}

View 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>

View File

@@ -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>

View 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;
}

View 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>

View File

@@ -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);
}
}
}