Skip to content

Commit

Permalink
fix(ios): scroll view setZoomScale()/setContentOffset() crash as of 1…
Browse files Browse the repository at this point in the history
…0.0.0

Fixes TIMOB-28443
  • Loading branch information
jquick-axway authored and sgtcoolguy committed May 10, 2021
1 parent 8859403 commit e7c5ff3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions iphone/Classes/TiUIScrollViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ - (void)scrollToTop:(id)unused
YES);
}

- (void)setContentOffset:(id)args
{
id arg1 = args;
id arg2 = nil;
if ([args isKindOfClass:[NSArray class]]) {
arg1 = VALUE_AT_INDEX_OR_NIL(args, 0);
arg2 = VALUE_AT_INDEX_OR_NIL(args, 1);
}
[self setContentOffset:arg1 withObject:arg2];
}

- (void)setContentOffset:(id)value withObject:(id)animated
{
TiThreadPerformOnMainThread(
Expand All @@ -358,6 +369,17 @@ - (void)setContentOffset:(id)value withObject:(id)animated
YES);
}

- (void)setZoomScale:(id)args
{
id arg1 = args;
id arg2 = nil;
if ([args isKindOfClass:[NSArray class]]) {
arg1 = VALUE_AT_INDEX_OR_NIL(args, 0);
arg2 = VALUE_AT_INDEX_OR_NIL(args, 1);
}
[self setZoomScale:arg1 withObject:arg2];
}

- (void)setZoomScale:(id)value withObject:(id)animated
{
TiThreadPerformOnMainThread(
Expand Down
32 changes: 32 additions & 0 deletions tests/Resources/ti.ui.scrollview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ describe('Titanium.UI.ScrollView', function () {
should(bar.contentOffset.y).be.a.Number();
});

it.ios('#setContentOffset', function (finish) {
win = Ti.UI.createWindow();
const bar = Ti.UI.createScrollView({});
win.add(bar);
win.addEventListener('postlayout', function listener(e) {
win.removeEventListener(e.type, listener);
try {
bar.setContentOffset({ x: 0, y: 0 }, { animated: true });
} catch (err) {
return finish(err);
}
finish();
});
win.open();
});

it.androidAndIosBroken('contentWidth', function () {
const bar = Ti.UI.createScrollView({});
should(bar.contentWidth).be.a.String(); // defaults to undefined on Android and iOS
Expand Down Expand Up @@ -153,6 +169,22 @@ describe('Titanium.UI.ScrollView', function () {
should(bar.zoomScale).be.a.Number();
});

it.androidMissing('#setZoomScale', function (finish) {
win = Ti.UI.createWindow();
const bar = Ti.UI.createScrollView({});
win.add(bar);
win.addEventListener('postlayout', function listener(e) {
win.removeEventListener(e.type, listener);
try {
bar.setZoomScale(2, { animated: true });
} catch (err) {
return finish(err);
}
finish();
});
win.open();
});

it('#scrollTo()', function () {
const bar = Ti.UI.createScrollView({});
should(bar.scrollTo).be.a.Function();
Expand Down

0 comments on commit e7c5ff3

Please sign in to comment.