Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Fix: hide UIPageControl #8

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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