Skip to content

Commit

Permalink
fix: convertPointToView() to apply ScrollView contentOffset
Browse files Browse the repository at this point in the history
Fixes TIMOB-28398
  • Loading branch information
jquick-axway authored and ewanharris committed Jun 18, 2021
1 parent f0cc76a commit a9d6c7d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
Expand Up @@ -940,6 +940,12 @@ public TiScrollViewLayout getLayout()
return null;
}

@Override
public View getNativeContentView()
{
return getLayout();
}

public void setScrollingEnabled(Object value)
{
try {
Expand Down
Expand Up @@ -1276,7 +1276,7 @@ public KrollDict convertPointToView(KrollDict point, TiViewProxy dest)
return null;
}
View nativeView = view.getNativeView();
View destNativeView = destView.getNativeView();
View destNativeView = destView.getNativeContentView();
if (nativeView == null || nativeView.getParent() == null) {
Log.w(TAG, "convertPointToView: View has not been attached, cannot convert point");
return null;
Expand Down
Expand Up @@ -298,6 +298,20 @@ public LayoutParams getLayoutParams()
return layoutParams;
}

/**
* Gets the native view's internal content view used to host child views.
* Called by the convertPointToView() method to convert coordinates.
* <p>
* Overridden by ScrollView since its content view is typically larger than the parent view.
* <p>
* For most other views, this method returns same view as getNativeView() method.
* @return Returns the native content view used to host child views.
*/
public View getNativeContentView()
{
return getNativeView();
}

/**
* @return the Android native view.
*/
Expand Down
2 changes: 2 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiPoint.h
Expand Up @@ -25,6 +25,8 @@

- (void)setValues:(id)object;

- (void)add:(TiPoint *)value;

/**
Provides access to point struct.
*/
Expand Down
13 changes: 13 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiPoint.m
Expand Up @@ -38,6 +38,19 @@ - (void)setValues:(id)object
}
}

- (void)add:(TiPoint *)value
{
if (!value) {
return;
}

CGPoint offsetPoint = [value point];
CGPoint newPoint = [self point];
newPoint.x += offsetPoint.x;
newPoint.y += offsetPoint.y;
[self setPoint:newPoint];
}

- (void)setPoint:(CGPoint)point_
{
xDimension = TiDimensionDip(point_.x);
Expand Down
1 change: 1 addition & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiViewProxy.h
Expand Up @@ -243,6 +243,7 @@ enum {

- (void)setBackgroundGradient:(id)arg;
- (TiBlob *)toImage:(id)args;
- (TiPoint *)contentOffset;

#pragma mark nonpublic accessors not related to Housecleaning

Expand Down
6 changes: 6 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiViewProxy.m
Expand Up @@ -737,6 +737,11 @@ - (TiBlob *)toImage:(id)args
return blob;
}

- (TiPoint *)contentOffset
{
return [[[TiPoint alloc] initWithPoint:CGPointMake(0, 0)] autorelease];
}

- (TiPoint *)convertPointToView:(id)args
{
id arg1 = nil;
Expand Down Expand Up @@ -765,6 +770,7 @@ - (TiPoint *)convertPointToView:(id)args
TiPoint *tiPoint = [[TiPoint alloc] autorelease];
[tiPoint setX:NUMFLOAT(convertDipToDefaultUnit(pointOffsetDips.x + givenPoint.x))];
[tiPoint setY:NUMFLOAT(convertDipToDefaultUnit(pointOffsetDips.y + givenPoint.y))];
[tiPoint add:[arg2 contentOffset]];
return tiPoint;
}

Expand Down

0 comments on commit a9d6c7d

Please sign in to comment.