Skip to content

Commit 0850252

Browse files
authored
fix(android): 'isEnabled' now works properly for SegmentedBar (NativeScript#8711)
1 parent 979130d commit 0850252

7 files changed

Lines changed: 72 additions & 13 deletions

File tree

e2e/ui-tests-app/app/main-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function pageLoaded(args: EventData) {
2929
examples.set("page", "page/main-page");
3030
examples.set("perf", "perf/main-page");
3131
examples.set("scroll-view", "scroll-view/main-page");
32-
examples.set("segStyle", "segmented-bar/all-page");
32+
examples.set("segmented-bar", "segmented-bar/main-page");
3333
examples.set("search-bar", "search-bar/main-page");
3434
examples.set("tab-view", "tab-view/main-page");
3535
examples.set("timePicker", "time-picker/time-picker-page");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as frame from "tns-core-modules/ui/frame";
2+
3+
export function navigate() {
4+
frame.topmost().goBack();
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Page>
2+
<StackLayout>
3+
<SegmentedBar selectedIndex="1" isEnabled="false">
4+
<SegmentedBarItem title="Item 1" />
5+
<SegmentedBarItem title="Item 2" />
6+
<SegmentedBarItem title="Item 3" />
7+
</SegmentedBar>
8+
<Button text="go to previous page" tap="navigate" />
9+
</StackLayout>
10+
</Page>
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Page>
2-
<StackLayout>
3-
<SegmentedBar selectedIndex="1">
4-
<SegmentedBar.items>
5-
<SegmentedBarItem title="Item 1" />
6-
<SegmentedBarItem title="Item 2" />
7-
<SegmentedBarItem title="Item 3" />
8-
</SegmentedBar.items>
9-
</SegmentedBar>
10-
<Button text="go to previous page" tap="navigate"/>
11-
</StackLayout>
12-
</Page>
2+
<StackLayout>
3+
<SegmentedBar selectedIndex="1">
4+
<SegmentedBar.items>
5+
<SegmentedBarItem title="Item 1" />
6+
<SegmentedBarItem title="Item 2" />
7+
<SegmentedBarItem title="Item 3" />
8+
</SegmentedBar.items>
9+
</SegmentedBar>
10+
<Button text="go to previous page" tap="navigate" />
11+
</StackLayout>
12+
</Page>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { EventData } from "tns-core-modules/data/observable";
2+
import { SubMainPageViewModel } from "../sub-main-page-view-model";
3+
import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout";
4+
import { Page } from "tns-core-modules/ui/page";
5+
6+
export function pageLoaded(args: EventData) {
7+
const page = <Page>args.object;
8+
const wrapLayout = <WrapLayout>page.getViewById("wrapLayoutWithExamples");
9+
page.bindingContext = new SubMainPageViewModel(wrapLayout, loadExamples());
10+
}
11+
12+
export function loadExamples() {
13+
const examples = new Map<string, string>();
14+
examples.set("segStyle", "segmented-bar/all-page");
15+
examples.set("clean", "segmented-bar/clean-page");
16+
examples.set("android-enabled", "segmented-bar/android-enabled-page");
17+
18+
return examples;
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Page loaded="pageLoaded">
3+
<ScrollView orientation="vertical" row="1">
4+
<WrapLayout id="wrapLayoutWithExamples"/>
5+
</ScrollView>
6+
</Page>

nativescript-core/ui/segmented-bar/segmented-bar.android.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Font } from "../styling/font";
22
import {
3-
SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsProperty, selectedBackgroundColorProperty,
3+
SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsProperty, isEnabledProperty, selectedBackgroundColorProperty,
44
colorProperty, fontInternalProperty, fontSizeProperty, Color, layout
55
} from "./segmented-bar-common";
66

@@ -30,6 +30,7 @@ let TabHost: TabHost;
3030
let TabChangeListener: TabChangeListener;
3131
let TabContentFactory: TabContentFactory;
3232

33+
// TODO: All TabHost public methods become deprecated in API 30.
3334
function initializeNativeClasses(): void {
3435
if (TabChangeListener) {
3536
return;
@@ -238,6 +239,17 @@ export class SegmentedBar extends SegmentedBarBase {
238239
super.disposeNativeView();
239240
}
240241

242+
public onLoaded() {
243+
super.onLoaded();
244+
245+
// Can only be applied after view is loaded
246+
const tabWidget = this.nativeViewProtected.getTabWidget();
247+
if (tabWidget)
248+
{
249+
tabWidget.setEnabled(tabWidget.isEnabled());
250+
}
251+
}
252+
241253
private insertTab(tabItem: SegmentedBarItem, index: number): void {
242254
const tabHost = this.nativeViewProtected;
243255
const tab = tabHost.newTabSpec(index + "");
@@ -270,4 +282,11 @@ export class SegmentedBar extends SegmentedBarBase {
270282

271283
selectedIndexProperty.coerce(this);
272284
}
285+
[isEnabledProperty.setNative](value: boolean) {
286+
const tabWidget = this.nativeViewProtected.getTabWidget();
287+
if (tabWidget)
288+
{
289+
tabWidget.setEnabled(value);
290+
}
291+
}
273292
}

0 commit comments

Comments
 (0)