Skip to content

Commit

Permalink
feat(android): add contentSize to Ti.UI.ScrollView scroll event
Browse files Browse the repository at this point in the history
Fixes TIMOB-27283
  • Loading branch information
m1ga authored and sgtcoolguy committed Sep 9, 2019
1 parent 722d6bc commit 6ffd9d4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@
*/
package ti.modules.titanium.ui.widget;

import java.util.HashMap;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiUIView;
import org.xmlpull.v1.XmlPullParser;

import ti.modules.titanium.ui.RefreshControlProxy;

import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
Expand All @@ -40,6 +22,22 @@
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import java.util.HashMap;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiUIView;
import org.xmlpull.v1.XmlPullParser;
import ti.modules.titanium.ui.RefreshControlProxy;
import ti.modules.titanium.ui.ScrollViewProxy;

public class TiUIScrollView extends TiUIView
{
Expand Down Expand Up @@ -448,9 +446,11 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt)
KrollDict data = new KrollDict();
getProxy().fireEvent(TiC.EVENT_DRAGSTART, data);
}

KrollDict data = new KrollDict();
data.put(TiC.EVENT_PROPERTY_X, l);
data.put(TiC.EVENT_PROPERTY_Y, t);
data.put(TiC.PROPERTY_CONTENT_SIZE, contentSize());
setContentOffset(l, t);
getProxy().fireEvent(TiC.EVENT_SCROLL, data);
}
Expand Down Expand Up @@ -575,13 +575,16 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
super.onScrollChanged(l, t, oldl, oldt);
KrollDict data = new KrollDict();

if (!isScrolling && isTouching) {
isScrolling = true;
getProxy().fireEvent(TiC.EVENT_DRAGSTART, data);
}

data = new KrollDict();
data.put(TiC.EVENT_PROPERTY_X, l);
data.put(TiC.EVENT_PROPERTY_Y, t);
data.put(TiC.PROPERTY_CONTENT_SIZE, contentSize());
setContentOffset(l, t);
getProxy().fireEvent(TiC.EVENT_SCROLL, data);
}
Expand Down Expand Up @@ -1061,6 +1064,19 @@ public void scrollToTop()
}
}

private KrollDict contentSize()
{
TiDimension dimensionWidth = new TiDimension(getLayout().getMeasuredWidth(), TiDimension.TYPE_WIDTH);
TiDimension dimensionHeight = new TiDimension(getLayout().getMeasuredHeight(), TiDimension.TYPE_HEIGHT);
double contentWidth = dimensionWidth.getAsDefault(getNativeView());
double contentHeight = dimensionHeight.getAsDefault(getNativeView());

KrollDict contentData = new KrollDict();
contentData.put(TiC.PROPERTY_WIDTH, contentWidth);
contentData.put(TiC.PROPERTY_HEIGHT, contentHeight);
return contentData;
}

@Override
public void add(TiUIView child)
{
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,11 @@ public class TiC
*/
public static final String PROPERTY_CONTENT_HEIGHT = "contentHeight";

/**
* @module.api
*/
public static final String PROPERTY_CONTENT_SIZE = "contentSize";

/**
* @module.api
*/
Expand Down
4 changes: 2 additions & 2 deletions apidoc/Titanium/UI/ScrollView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ events:
- name: contentSize
summary: |
The current content size of the scroll view defined by its `width` and `height` properties.
Available in Titanium SDK 5.2.0 and later.
type: Dictionary
platforms: [iphone, ipad]
platforms: [android, iphone, ipad]
since: { iphone: "5.2.0", ipad: "5.2.0", android: "8.3.0" }

- name: decelerating
summary: Indicates whether the scroll is decelerating.
Expand Down

0 comments on commit 6ffd9d4

Please sign in to comment.