Skip to content

Commit

Permalink
Merge pull request #8 from ddfreiling/ios-fixes
Browse files Browse the repository at this point in the history
iOS Fix: hide UIPageControl
  • Loading branch information
triniwiz authored Feb 17, 2017
2 parents c2dad59 + 6e555ed commit d5fb7d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Button text="Last" tap="lastPage" />
</StackLayout>

<c:Pager row="2" id="pager" pagesCount="5">
<c:Pager row="2" id="pager" pagesCount="10" showNativePageIndicator="true" backgroundColor="lightsteelblue">
<Pager.items>
<GridLayout rows="auto, *, auto" columns="*" class="pager-page">
<Label text="Slide 1"></Label>
Expand Down
7 changes: 7 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export abstract class Pager extends View implements AddArrayFromBuilder {
private _pageSpacing: number = 0;
public static selectedIndexProperty = new Property("selectedIndex", "Pager", new PropertyMetadata(0, PropertyMetadataSettings.None, null, null, onSelectedIndexChanged));
public static itemsProperty = new Property("items", "Pager", new PropertyMetadata(undefined, PropertyMetadataSettings.AffectsLayout, null, null, onItemsChanged));
public static showNativePageIndicatorProperty = new Property("showNativePageIndicator", "Pager", new PropertyMetadata(false));
public static selectedIndexChangedEvent = "selectedIndexChanged";

public _addArrayFromBuilder(name: string, value: Array<any>) {
Expand Down Expand Up @@ -67,6 +68,12 @@ export abstract class Pager extends View implements AddArrayFromBuilder {
set pageSpacing(value: number) {
this._pageSpacing = value;
}
get showNativePageIndicator() {
return this._getValue(Pager.showNativePageIndicatorProperty);
}
set showNativePageIndicator(value: boolean) {
this._setValue(Pager.showNativePageIndicatorProperty, value);
}
public abstract updateNativeItems(oldItems: Array<View>, newItems: Array<View>): void;

public abstract updateNativeIndex(oldIndex: number, newIndex: number): void;
Expand Down
16 changes: 5 additions & 11 deletions src/ios/pager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export class Pager extends common.Pager {
this._ios = UIPageViewController.alloc().initWithTransitionStyleNavigationOrientationOptions(this._transformer, this._orientation, this._options);
this._ios.dataSource = PagerDataSource.initWithOwner(that);
this._ios.delegate = PagerViewControllerDelegate.initWithOwner(that);
const pc = this._nativeView.subviews[0];
pc.hidden = true;
const sv = this._nativeView.subviews[1];
if (this.borderRadius) {
sv.layer.cornerRadius = this.borderRadius;
Expand All @@ -63,10 +61,6 @@ export class Pager extends common.Pager {
if (this.borderWidth) {
sv.layer.borderWidth = this.borderWidth;
}
// this._ios.view.sendSubviewToBack(pc)
// this._ios.view.frame = CGRectMake(0, 0, utils.ios.getter(UIScreen, UIScreen.mainScreen.bounds).size.width, utils.ios.getter(UIScreen, UIScreen.mainScreen.bounds).size.height - 300);
// sv.frame = CGRectMake(0, 0, sv.frame.size.width, sv.frame.size.height);
// sv.setNeedsLayout();
}

get views() {
Expand Down Expand Up @@ -253,7 +247,7 @@ class PagerDataSource extends NSObject implements UIPageViewControllerDataSource

pageViewControllerViewControllerBeforeViewController(pageViewController: UIPageViewController, viewControllerBefore: UIViewController): UIViewController {
let pos = (<PagerView>viewControllerBefore).tag;
if (pos === 0) {
if (pos === 0 || !this.owner || !this.owner.items) {
return null;
} else {
let prev = pos - 1;
Expand All @@ -263,17 +257,17 @@ class PagerDataSource extends NSObject implements UIPageViewControllerDataSource

pageViewControllerViewControllerAfterViewController(pageViewController: UIPageViewController, viewControllerAfter: UIViewController): UIViewController {
let pos = (<PagerView>viewControllerAfter).tag;
let count = this.presentationCountForPageViewController(pageViewController);
if (pos === count - 1) {
if (!this.owner || !this.owner.items || this.owner.items.length - 1 === pos) {
return null;
} else {
return this.owner.getViewController(pos + 1);
}
}

presentationCountForPageViewController(pageViewController: UIPageViewController): number {
if (!this.owner || !this.owner.items) {
return 0;
if (!this.owner || !this.owner.items || !this.owner.showNativePageIndicator) {
// Hide the native UIPageControl (dots)
return -1;
}
return this.owner.items.length;
}
Expand Down

0 comments on commit d5fb7d4

Please sign in to comment.