Skip to content

Commit

Permalink
fix(android): custom renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Aug 2, 2019
1 parent f7092a0 commit 0595f68
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-pager",
"version": "11.0.6",
"version": "11.0.7",
"description": "A Carousel/Pager plugin for NativeScript",
"main": "pager",
"typings": "pager.d.ts",
Expand Down
33 changes: 27 additions & 6 deletions src/pager.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function notifyForItemAtIndex(

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

export class Pager extends PagerBase {
nativeViewProtected: any; /* androidx.viewpager2.widget.ViewPager2 */
Expand Down Expand Up @@ -646,9 +647,13 @@ function initPagerRecyclerAdapter() {
const template = owner._itemTemplatesInternal[type];

let view: View =
template.createView() || owner._getDefaultItemContent(type);
template.createView();
let sp = new StackLayout();
sp.addChild(view);
if (view) {
sp.addChild(view);
} else {
sp[PLACEHOLDER] = true;
}
owner._addView(sp);
sp.nativeView.setLayoutParams(
new android.view.ViewGroup.LayoutParams(
Expand Down Expand Up @@ -677,10 +682,18 @@ function initPagerRecyclerAdapter() {
android: holder,
ios: undefined,
index,
view: holder.view
view: holder.view[PLACEHOLDER] ? null : holder.view
};

owner.notify(args);
if (holder.view[PLACEHOLDER]) {
if (args.view) {
holder.view.addChild(args.view);
} else {
holder.view.addChild(owner._getDefaultItemContent(index));
}
holder.view[PLACEHOLDER] = false;
}
owner._prepareItem(holder.view, index);
}
}
Expand Down Expand Up @@ -746,10 +759,12 @@ function initStaticPagerStateAdapter() {

const view = owner._childrenViews.get(type);
let sp = new StackLayout(); // Pager2 requires match_parent so add a parent with to fill
if (!view.parent) {
if (view && !view.parent) {
sp.addChild(view);
owner._addView(sp);
} else {
sp[PLACEHOLDER] = true;
}
owner._addView(sp);

sp.nativeView.setLayoutParams(
new android.view.ViewGroup.LayoutParams(
Expand Down Expand Up @@ -777,10 +792,16 @@ function initStaticPagerStateAdapter() {
android: holder,
ios: undefined,
index,
view: holder.view
view: holder.view[PLACEHOLDER] ? null : holder.view
};

owner.notify(args);
if (holder.view[PLACEHOLDER]) {
if (args.view) {
holder.view.addChild(args.view);
}
holder.view[PLACEHOLDER] = false;
}
}
}

Expand Down

0 comments on commit 0595f68

Please sign in to comment.