feat(tabs): animationEnabled property

This commit is contained in:
rigor789
2020-07-11 15:53:54 +02:00
parent 8eb98cec4e
commit 0e0f2bc9dd
4 changed files with 29 additions and 17 deletions

View File

@@ -45,5 +45,5 @@ export type IOSTabBarItemsAlignment = "leading" | "justified" | "center" | "cent
export const iOSTabBarItemsAlignmentProperty = new Property<TabsBase, IOSTabBarItemsAlignment>({ name: "iOSTabBarItemsAlignment", defaultValue: "justified" });
iOSTabBarItemsAlignmentProperty.register(TabsBase);
export const iOSAnimationEnabledProperty = new Property<TabsBase, boolean>({ name: "iOSAnimationEnabled", defaultValue: true, valueConverter: booleanConverter });
iOSAnimationEnabledProperty.register(TabsBase);
export const animationEnabledProperty = new Property<TabsBase, boolean>({ name: "animationEnabled", defaultValue: true, valueConverter: booleanConverter });
animationEnabledProperty.register(TabsBase);

View File

@@ -15,7 +15,7 @@ import {
getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty
} from "../tab-navigation-base/tab-navigation-base";
import { getTransformedText } from "../text-base";
import { offscreenTabLimitProperty, swipeEnabledProperty, TabsBase } from "./tabs-common";
import { offscreenTabLimitProperty, swipeEnabledProperty, animationEnabledProperty, TabsBase } from "./tabs-common";
export * from "./tabs-common";
@@ -378,6 +378,7 @@ export class Tabs extends TabsBase {
private _textTransform: TextTransform = "uppercase";
private _selectedItemColor: Color;
private _unSelectedItemColor: Color;
public animationEnabled: boolean;
constructor() {
super();
@@ -946,14 +947,11 @@ export class Tabs extends TabsBase {
}
[selectedIndexProperty.setNative](value: number) {
const smoothScroll = true;
// TODO
// if (traceEnabled()) {
// traceWrite("TabView this._viewPager.setCurrentItem(" + value + ", " + smoothScroll + ");", traceCategory);
// }
this._viewPager.setCurrentItem(value, smoothScroll);
this._viewPager.setCurrentItem(value, this.animationEnabled);
}
[itemsProperty.getDefault](): TabContentItem[] {
@@ -985,6 +983,10 @@ export class Tabs extends TabsBase {
[offscreenTabLimitProperty.setNative](value: number) {
this._viewPager.setOffscreenPageLimit(value);
}
[animationEnabledProperty.setNative](value: number) {
(<any>this._viewPager).setAnimationEnabled(value);
}
}
function tryCloneDrawable(value: android.graphics.drawable.Drawable, resources: android.content.res.Resources): android.graphics.drawable.Drawable {

View File

@@ -13,9 +13,17 @@ import { ios as iosView, View } from "../core/view";
import { Frame } from "../frame";
import { Font } from "../styling/font";
import {
getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty,
getIconSpecSize,
itemsProperty,
selectedIndexProperty,
tabStripProperty,
} from "../tab-navigation-base/tab-navigation-base";
import { swipeEnabledProperty, TabsBase, IOSTabBarItemsAlignment, iOSTabBarItemsAlignmentProperty } from "./tabs-common";
import {
IOSTabBarItemsAlignment,
iOSTabBarItemsAlignmentProperty,
swipeEnabledProperty,
TabsBase
} from "./tabs-common";
// TODO
// import { profile } from "../../profiling";
@@ -463,7 +471,7 @@ export class Tabs extends TabsBase {
public _defaultItemBackgroundColor: UIColor;
private _selectedItemColor: Color;
private _unSelectedItemColor: Color;
public iOSAnimationEnabled: boolean;
public animationEnabled: boolean;
constructor() {
super();
@@ -1103,7 +1111,7 @@ export class Tabs extends TabsBase {
// do not make layout changes while the animation is in progress https://stackoverflow.com/a/47031524/613113
this.visitFrames(item, frame => frame._animationInProgress = true);
invokeOnRunLoop( () => this.viewController.setViewControllersDirectionAnimatedCompletion(controllers, navigationDirection, this.iOSAnimationEnabled, (finished: boolean) => {
invokeOnRunLoop( () => this.viewController.setViewControllersDirectionAnimatedCompletion(controllers, navigationDirection, this.animationEnabled, (finished: boolean) => {
this.visitFrames(item, frame => frame._animationInProgress = false);
if (finished) {
// HACK: UIPageViewController fix; see https://stackoverflow.com/a/17330606
@@ -1116,7 +1124,7 @@ export class Tabs extends TabsBase {
}));
if (this.tabBarItems && this.tabBarItems.length && this.viewController && this.viewController.tabBar) {
this.viewController.tabBar.setSelectedItemAnimated(this.tabBarItems[value], this.iOSAnimationEnabled);
this.viewController.tabBar.setSelectedItemAnimated(this.tabBarItems[value], this.animationEnabled);
}
// TODO:
// (<any>this._ios)._willSelectViewController = this._ios.viewControllers[value];