Skip to content

Commit

Permalink
[TIMOB-26168] Fix initializing of scrollbars
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Aug 3, 2018
1 parent 1b25f7a commit 6b7684a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="horizontal"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical"/>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
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;

Expand All @@ -28,6 +30,8 @@
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.util.Xml;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -51,6 +55,9 @@ public class TiUIScrollView extends TiUIView
private boolean isScrolling = false;
private boolean isTouching = false;

private static int verticalAttrId = -1;
private static int horizontalAttrId = -1;

public class TiScrollViewLayout extends TiCompositeLayout
{
private static final int AUTO = Integer.MAX_VALUE;
Expand Down Expand Up @@ -315,14 +322,34 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
}
}

// TIMOB-26168: if 'android:scrollbars' is not defined then our scrollbars will never be initialized
// so we do this our selves
private AttributeSet getAttributeSet(Context context, int resourceId)
{
AttributeSet attr = null;
try {
XmlPullParser parser = context.getResources().getXml(resourceId);
try {
parser.next();
parser.nextTag();
} catch (Exception e) {
// ignore...
}
attr = Xml.asAttributeSet(parser);
} catch (Exception e) {
// ignore...
}
return attr;
}

// same code, different super-classes
private class TiVerticalScrollView extends NestedScrollView
{
private TiScrollViewLayout layout;

public TiVerticalScrollView(Context context, LayoutArrangement arrangement)
{
super(context);
super(context, getAttributeSet(context, verticalAttrId));

// TIMOB-25359: allow window to re-size when keyboard is shown
if (context instanceof TiBaseActivity) {
Expand Down Expand Up @@ -475,7 +502,7 @@ private class TiHorizontalScrollView extends HorizontalScrollView implements Nes

public TiHorizontalScrollView(Context context, LayoutArrangement arrangement)
{
super(context);
super(context, getAttributeSet(context, horizontalAttrId));
setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
setScrollContainer(true);

Expand Down Expand Up @@ -690,6 +717,13 @@ public TiUIScrollView(TiViewProxy proxy)
super(proxy);
getLayoutParams().autoFillsHeight = true;
getLayoutParams().autoFillsWidth = true;

try {
verticalAttrId = TiRHelper.getResource("xml.titanium_ui_vertical_nested_scrollview");
horizontalAttrId = TiRHelper.getResource("xml.titanium_ui_horizontal_nested_scrollview");
} catch (Exception e) {
Log.w(TAG, "could not load NestedScrollView attributes");
}
}

@Override
Expand Down

0 comments on commit 6b7684a

Please sign in to comment.