Skip to content

Commit 50a9bd5

Browse files
committed
chore: working on overlap property
1 parent 09276e7 commit 50a9bd5

File tree

7 files changed

+952
-10
lines changed

7 files changed

+952
-10
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nativescript.collectionview">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nativescript.collectionview" >
33
</manifest>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
dependencies {
22
def androidXRecyclerViewVersion = project.hasProperty("androidXRecyclerViewVersion") ? project.androidXRecyclerViewVersion : "1.3.0"
33
implementation "androidx.recyclerview:recyclerview:$androidXRecyclerViewVersion"
4-
implementation ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:1.0.0@aar'){
5-
transitive=true
6-
}
4+
// implementation ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:1.0.0@aar'){
5+
// transitive=true
6+
// }
7+
implementation 'jp.wasabeef:recyclerview-animators:4.0.2'
78
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.nativescript.collectionview;
2+
import androidx.recyclerview.widget.RecyclerView;
3+
import android.view.View;
4+
import android.graphics.Rect;
5+
6+
public class OverlapDecoration extends RecyclerView.ItemDecoration {
7+
8+
public int top = 0;
9+
public int right = 0;
10+
public int bottom = 0;
11+
public int left = 0;
12+
13+
@Override
14+
public void getItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
15+
final int itemPosition = parent.getChildAdapterPosition(view);
16+
int position = parent.getChildAdapterPosition(view);
17+
boolean isLast = position == state.getItemCount()-1;
18+
if (itemPosition == 0) {
19+
return; }
20+
outRect.set(left, top, right, bottom);
21+
}
22+
}

src/collectionview/index-common.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ItemsSource,
88
KeyedTemplate,
99
Label,
10+
Length,
1011
Observable,
1112
ObservableArray,
1213
PercentLength,
@@ -743,3 +744,60 @@ export const autoReloadItemOnLayoutProperty = new Property<CollectionViewBase, b
743744
valueConverter: booleanConverter
744745
});
745746
autoReloadItemOnLayoutProperty.register(CollectionViewBase);
747+
748+
function parseThickness(value: string): any {
749+
if (typeof value === 'string') {
750+
const arr = value.split(/[ ,]+/);
751+
752+
let top: string;
753+
let right: string;
754+
let bottom: string;
755+
let left: string;
756+
757+
if (arr.length === 1) {
758+
top = arr[0];
759+
right = arr[0];
760+
bottom = arr[0];
761+
left = arr[0];
762+
} else if (arr.length === 2) {
763+
top = arr[0];
764+
bottom = arr[0];
765+
right = arr[1];
766+
left = arr[1];
767+
} else if (arr.length === 3) {
768+
top = arr[0];
769+
right = arr[1];
770+
left = arr[1];
771+
bottom = arr[2];
772+
} else if (arr.length === 4) {
773+
top = arr[0];
774+
right = arr[1];
775+
bottom = arr[2];
776+
left = arr[3];
777+
} else {
778+
throw new Error('Expected 1, 2, 3 or 4 parameters. Actual: ' + value);
779+
}
780+
781+
return {
782+
top,
783+
right,
784+
bottom,
785+
left
786+
};
787+
} else {
788+
return value;
789+
}
790+
}
791+
export const itemOverlapProperty = new Property<CollectionViewBase, CoreTypes.LengthType[]>({
792+
name: 'itemOverlap',
793+
valueConverter: (value) => {
794+
if (typeof value === 'string' && value !== 'auto') {
795+
const thickness = parseThickness(value);
796+
797+
return [Length.parse(thickness.top), Length.parse(thickness.right), Length.parse(thickness.bottom), Length.parse(thickness.left)];
798+
} else {
799+
return [value, value, value, value];
800+
}
801+
}
802+
});
803+
itemOverlapProperty.register(CollectionViewBase);

src/collectionview/index.android.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ChangedData,
55
ContentView,
66
CoreTypes,
7+
Length,
78
Property,
89
ProxyViewContainer,
910
Trace,
@@ -17,7 +18,7 @@ import {
1718
paddingTopProperty,
1819
profile
1920
} from '@nativescript/core';
20-
import { CollectionViewItemEventData, Orientation, reorderLongPressEnabledProperty, reorderingEnabledProperty, reverseLayoutProperty, scrollBarIndicatorVisibleProperty } from '.';
21+
import { CollectionViewItemEventData, Orientation, itemOverlapProperty, reorderLongPressEnabledProperty, reorderingEnabledProperty, reverseLayoutProperty, scrollBarIndicatorVisibleProperty } from '.';
2122
import { CLog, CLogTypes, CollectionViewBase, ListViewViewTypes, isScrollEnabledProperty, orientationProperty } from './index-common';
2223

2324
export * from './index-common';
@@ -176,7 +177,7 @@ export class CollectionView extends CollectionViewBase {
176177
if (!CollectionViewRecyclerView) {
177178
CollectionViewRecyclerView = com.nativescript.collectionview.RecyclerView as any;
178179
}
179-
const recyclerView = (CollectionViewRecyclerView as any).createRecyclerView(this._context);
180+
const recyclerView = (CollectionViewRecyclerView as any).createRecyclerView(this._context) as com.nativescript.collectionview.RecyclerView;
180181
// const expMgr = new RecyclerViewExpandableItemManager(null);
181182
// adapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(true); //Make headers sticky
182183
// Endless scroll with 1 item threshold
@@ -255,18 +256,18 @@ export class CollectionView extends CollectionViewBase {
255256
});
256257
this.spanSize = this._getSpanSize;
257258

258-
const animator = new com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator();
259-
259+
const animator = new jp.wasabeef.recyclerview.animators.FadeInAnimator();
260+
animator.setInterpolator(new android.view.animation.OvershootInterpolator());
261+
animator.setMoveDuration(200);
260262
// Change animations are enabled by default since support-v7-recyclerview v22.
261263
// Need to disable them when using animation indicator.
262-
animator.setSupportsChangeAnimations(false);
264+
// animator.setSupportsChangeAnimations(false);
263265

264266
nativeView.setItemAnimator(animator);
265267

266268
this.refresh();
267269
}
268270
public disposeNativeView() {
269-
// clear the cache
270271
// this.eachChildView((view) => {
271272
// view.parent._removeView(view);
272273
// return true;
@@ -524,6 +525,17 @@ export class CollectionView extends CollectionViewBase {
524525
[paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
525526
this._setPadding({ left: this.effectivePaddingLeft });
526527
}
528+
decorator: com.nativescript.collectionview.OverlapDecoration;
529+
[itemOverlapProperty.setNative](value: CoreTypes.LengthType[]) {
530+
if (!this.decorator) {
531+
this.decorator = new com.nativescript.collectionview.OverlapDecoration();
532+
this.nativeViewProtected.addItemDecoration(this.decorator);
533+
}
534+
this.decorator.top = Length.toDevicePixels(value[0], 0);
535+
this.decorator.right = Length.toDevicePixels(value[1], 0);
536+
this.decorator.bottom = Length.toDevicePixels(value[2], 0);
537+
this.decorator.left = Length.toDevicePixels(value[3], 0);
538+
}
527539

528540
public [orientationProperty.getDefault](): Orientation {
529541
return 'vertical';

src/collectionview/typings/android.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ declare namespace com {
7171
}
7272

7373
export class SmoothScroller extends androidx.recyclerview.widget.LinearSmoothScroller {}
74+
export class OverlapDecoration extends androidx.recyclerview.widget.RecyclerView.ItemDecoration {
75+
public top: number;
76+
public right: number;
77+
public bottom: number;
78+
public left: number;
79+
}
7480
}
7581
}
7682
}

0 commit comments

Comments
 (0)