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

feat(android): refreshControl offset property #13970

Merged
merged 8 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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("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 @@ -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
m1ga marked this conversation as resolved.
Show resolved Hide resolved
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
Loading