Skip to content

Commit

Permalink
feat(android): refreshControl offset property
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Jan 20, 2024
1 parent bfc87a6 commit 49ef22e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;

import ti.modules.titanium.ui.widget.TiSwipeRefreshLayout;

@Kroll.proxy(creatableInModule = UIModule.class,
Expand All @@ -25,7 +28,8 @@ public class RefreshControlProxy extends KrollProxy
{
/** The default Android log tag name to be used by this class. */
private static final String TAG = "RefreshControlProxy";

private static int offsetStart = -1;
private static int offsetEnd = -1;
/**
* Android's default progress indicator color used by the SwipeRefreshLayout class.
* This is defined in Google's "MaterialProgressDrawable.java", which is an internal class.
Expand Down Expand Up @@ -85,9 +89,18 @@ public void handleCreationDict(KrollDict properties)
super.handleCreationDict(properties);

// Fetch "tintColor" property, if provided.
value = properties.get(TiC.PROPERTY_TINT_COLOR);
if (value != null) {
onTintColorChanged(value);
if (properties.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR)) {
value = properties.get(TiC.PROPERTY_TINT_COLOR);
if (value != null) {
onTintColorChanged(value);
}
}
if (properties.containsKeyAndNotNull("offset")) {
KrollDict offset = properties.getKrollDict("offset");
offsetStart = new TiDimension(TiConvert.toInt(offset.get("top"), 0), TiDimension.TYPE_TOP)
.getAsPixels(this.swipeRefreshLayout);
offsetEnd = new TiDimension(TiConvert.toInt(offset.get("bottom"), 80), TiDimension.TYPE_BOTTOM)
.getAsPixels(this.swipeRefreshLayout);
}
}

Expand Down Expand Up @@ -221,6 +234,9 @@ public void assignTo(TiSwipeRefreshLayout view)

// Set up the given view for pull-down refresh support.
view.setColorSchemeColors(this.tintColor);
if (offsetStart != -1 && offsetEnd != -1) {
view.setProgressViewOffset(false, offsetStart, offsetEnd);
}
view.setSwipeRefreshEnabled(true);
view.setOnRefreshListener(new TiSwipeRefreshLayout.OnRefreshListener() {
@Override
Expand Down
17 changes: 17 additions & 0 deletions apidoc/Titanium/UI/RefreshControl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ properties:
platforms: [android, iphone, ipad, macos]
since: { android: "6.2.0", iphone: "3.2.0", ipad: "3.2.0" }

- name: offset
summary: Offset of the refresh control view.
type: refreshOffset
platforms: [android]
since: { android: "12.4.0" }
availability: creation

events:
- name: refreshstart
summary: |
Expand Down Expand Up @@ -138,3 +145,13 @@ examples:
$.index.open();
```
---
name: refreshOffset
summary: Offset of the refresh control view.
properties:
- name: top
summary: Top padding of the map view.
type: Number
- name: bottom
summary: Bottom padding of the map view.
type: Number

0 comments on commit 49ef22e

Please sign in to comment.