Skip to content

Commit

Permalink
feat(android): refreshControl offset property (#13970)
Browse files Browse the repository at this point in the history
* feat(android): refreshControl offset property

* feat(android): refreshControl offset property

* docs

* Update RefreshControl.yml

---------

Co-authored-by: Hans Knöchel <hansemannn@users.noreply.github.com>
  • Loading branch information
m1ga and hansemannn authored Dec 15, 2024
1 parent 70db837 commit 06248ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;

import java.util.HashSet;

Expand All @@ -30,7 +32,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 @@ -134,9 +137,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("start"), 0), TiDimension.TYPE_TOP)
.getAsPixels(this.swipeRefreshLayout);
offsetEnd = new TiDimension(TiConvert.toInt(offset.get("end"), 80), TiDimension.TYPE_BOTTOM)
.getAsPixels(this.swipeRefreshLayout);
}
}

Expand Down Expand Up @@ -275,6 +287,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()
{
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: RefreshControlOffset
platforms: [android]
since: { android: "12.7.0" }
availability: creation

- name: backgroundColor
summary: The background color for the refresh control, as a color name or hex triplet.
description: |
Expand Down Expand Up @@ -146,3 +153,13 @@ examples:
$.index.open();
```
---
name: RefreshControlOffset
summary: Offset of the refresh control view.
properties:
- name: start
summary: The offset from the top of this view at which the progress spinner should appear.
type: Number
- name: end
summary: The offset from the top of this view at which the progress spinner should come to rest after a successful swipe gesture.
type: Number

0 comments on commit 06248ec

Please sign in to comment.