Skip to content

Commit

Permalink
fix(android): 'isEnabled' now works properly for SegmentedBar (#8711)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatchABus authored Jul 22, 2020
1 parent 979130d commit 0850252
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 13 deletions.
2 changes: 1 addition & 1 deletion e2e/ui-tests-app/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions e2e/ui-tests-app/app/segmented-bar/android-enabled-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as frame from "tns-core-modules/ui/frame";

export function navigate() {
frame.topmost().goBack();
}
10 changes: 10 additions & 0 deletions e2e/ui-tests-app/app/segmented-bar/android-enabled-page.xml
Original file line number Diff line number Diff line change
@@ -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>
22 changes: 11 additions & 11 deletions e2e/ui-tests-app/app/segmented-bar/clean-page.xml
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions e2e/ui-tests-app/app/segmented-bar/main-page.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions e2e/ui-tests-app/app/segmented-bar/main-page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Page loaded="pageLoaded">
<ScrollView orientation="vertical" row="1">
<WrapLayout id="wrapLayoutWithExamples"/>
</ScrollView>
</Page>
21 changes: 20 additions & 1 deletion nativescript-core/ui/segmented-bar/segmented-bar.android.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 + "");
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 0850252

Please sign in to comment.