Skip to content

Commit

Permalink
Merge pull request #150 from bradmartin/master
Browse files Browse the repository at this point in the history
Fix orientation and closes #140
  • Loading branch information
triniwiz authored Oct 29, 2019
2 parents 7e4ce95 + ae177fe commit 0a4d7b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
67 changes: 24 additions & 43 deletions src/pager.android.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
import { ChangeType, ObservableArray } from 'tns-core-modules/data/observable-array';
import { screen } from 'tns-core-modules/platform';
import { KeyedTemplate, layout, Property, View } from 'tns-core-modules/ui/core/view';
import { StackLayout } from 'tns-core-modules/ui/layouts/stack-layout';
import { ChangeType, ObservableArray } from 'tns-core-modules/data/observable-array';
import * as types from 'tns-core-modules/utils/types';
import { screen } from 'tns-core-modules/platform/platform';
import {
disableSwipeProperty,
Indicator,
indicatorProperty,
ItemEventData,
ITEMLOADING,
itemsProperty,
itemTemplatesProperty,
LOADMOREITEMS,
Orientation,
orientationProperty,
PagerBase,
PagerItem,
peakingProperty,
selectedIndexProperty,
showIndicatorProperty,
spacingProperty,
Transformer
} from './pager.common';
import { disableSwipeProperty, Indicator, indicatorProperty, ItemEventData, ITEMLOADING, itemsProperty, itemTemplatesProperty, LOADMOREITEMS, Orientation, orientationProperty, PagerBase, PagerItem, peakingProperty, selectedIndexProperty, showIndicatorProperty, spacingProperty, Transformer } from './pager.common';

export * from './pager.common';
export { EventData, ItemsSource, Transformer } from './pager.common';

function notifyForItemAtIndex(
owner,
Expand All @@ -45,7 +28,6 @@ function notifyForItemAtIndex(
}

declare var java, android;
export { Transformer, EventData, ItemsSource } from './pager.common';
const PLACEHOLDER = 'PLACEHOLDER';

export class Pager extends PagerBase {
Expand Down Expand Up @@ -112,15 +94,11 @@ export class Pager extends PagerBase {
this._pager = new androidx.viewpager2.widget.ViewPager2(
this._context
);

if (this.orientation === 'vertical') {
this.pager.setOrientation(
androidx.viewpager2.widget.ViewPager2.ORIENTATION_VERTICAL
);
this._pager.setOrientation(androidx.viewpager2.widget.ViewPager2.ORIENTATION_VERTICAL);
} else {
this.pager.setOrientation(
androidx.viewpager2.widget.ViewPager2
.ORIENTATION_HORIZONTAL
);
this._pager.setOrientation(androidx.viewpager2.widget.ViewPager2.ORIENTATION_HORIZONTAL);
}

initPagerChangeCallback();
Expand Down Expand Up @@ -325,7 +303,7 @@ export class Pager extends PagerBase {
break;
}
}
}
};

public disposeNativeView() {
this.off(View.layoutChangedEvent, this.onLayoutChange, this);
Expand Down Expand Up @@ -386,7 +364,7 @@ export class Pager extends PagerBase {
const adapter = this.pagerAdapter;
if (!adapter) return;
selectedIndexProperty.coerce(this);
this._observableArrayInstance = value;
this._observableArrayInstance = value as any;
this._observableArrayInstance.on(ObservableArray.changeEvent, this._observableArrayHandler);
} else {
this.refresh();
Expand All @@ -409,15 +387,17 @@ export class Pager extends PagerBase {
super.onLoaded();
if (!this.items && this._childrenCount > 0) {
initStaticPagerStateAdapter();
this._pagerAdapter = new StaticPagerStateAdapter(new WeakRef(this));
this.pager.setAdapter(this._pagerAdapter);
selectedIndexProperty.coerce(this);
setTimeout(() => {
this.pager.setCurrentItem(
this.selectedIndex,
false
);
}, 0);
if (!(this._pagerAdapter instanceof StaticPagerStateAdapter)) {
this._pagerAdapter = new StaticPagerStateAdapter(new WeakRef(this));
this.pager.setAdapter(this._pagerAdapter);
selectedIndexProperty.coerce(this);
setTimeout(() => {
this.pager.setCurrentItem(
this.selectedIndex,
false
);
}, 0);
}
}
}

Expand Down Expand Up @@ -520,11 +500,11 @@ export class Pager extends PagerBase {

public [orientationProperty.setNative](value: Orientation) {
if (value === 'vertical') {
this.nativeViewProtected.setOrientation(
this._pager.setOrientation(
androidx.viewpager2.widget.ViewPager2.ORIENTATION_VERTICAL
);
} else {
this.nativeViewProtected.setOrientation(
this._pager.setOrientation(
androidx.viewpager2.widget.ViewPager2
.ORIENTATION_HORIZONTAL
);
Expand Down Expand Up @@ -895,6 +875,7 @@ function initZoomOutPageTransformer() {
return;
}


@Interfaces([androidx.viewpager2.widget.ViewPager2.PageTransformer])
class ZoomOutPageTransformerImpl extends java.lang.Object implements androidx.viewpager2.widget.ViewPager2.PageTransformer {
owner: WeakRef<Pager>;
Expand Down Expand Up @@ -949,4 +930,4 @@ function initZoomInPageTransformer() {
}

ZoomInPageTransformer = ZoomInPageTransformerImpl as any;
}
}
4 changes: 2 additions & 2 deletions src/platforms/android/include.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ repositories {
}

dependencies {
def androidxVersion = project.hasProperty("androidxVersion") ? project.androidxVersion : "1.0.0"
def androidxVersion = project.hasProperty("androidxVersion") ? project.androidxVersion : "1.1.0"

implementation "androidx.appcompat:appcompat:$androidxVersion"

implementation 'androidx.viewpager2:viewpager2:1.0.0-beta04'
implementation 'androidx.viewpager2:viewpager2:1.0.0-rc01'

implementation 'com.github.adrielcafe:PageIndicatorView:1.0.6'
}

0 comments on commit 0a4d7b5

Please sign in to comment.