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

fix(ios): ScrollView setZoomScale()/setContentOffset() methods crash as of 10.0.0 #12788

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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