From 8e3b68d4629fe84dd0cb0ee08c45d1037e8a0d3a Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 23 Feb 2011 02:49:30 -0800 Subject: Add cydia.scrollToBottom(). --- MobileCydia.mm | 6 ++++++ UICaboodle/BrowserView.mm | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/MobileCydia.mm b/MobileCydia.mm index 51843a7..948bb60 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4001,6 +4001,8 @@ static NSString *Warning_; return @"refreshSources"; else if (selector == @selector(removeButton)) return @"removeButton"; + else if (selector == @selector(scrollToBottom:)) + return @"scrollToBottom"; else if (selector == @selector(setButtonImage:withStyle:toFunction:)) return @"setButtonImage"; else if (selector == @selector(setButtonTitle:withStyle:toFunction:)) @@ -4184,6 +4186,10 @@ static NSString *Warning_; [indirect_ setPopupHook:function]; } +- (void) scrollToBottom:(NSNumber *)animated { + [indirect_ performSelectorOnMainThread:@selector(scrollToBottomAnimated:) withObject:animated waitUntilDone:NO]; +} + - (void) setViewportWidth:(float)width { [indirect_ setViewportWidthOnMainThread:width]; } diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 07a92ee..d5116cf 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -601,6 +601,17 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se closer_ = [function retain]; } +- (void) scrollToBottomAnimated:(NSNumber *)animated { + CGSize size([scroller_ contentSize]); + CGPoint offset([scroller_ contentOffset]); + CGRect frame([scroller_ frame]); + + if (size.height - offset.y < frame.size.height + 20.f) { + CGRect rect = {{0, size.height-1}, {size.width, 1}}; + [scroller_ scrollRectToVisible:rect animated:[animated boolValue]]; + } +} + - (void) _setViewportWidth { [[webview_ _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; } -- cgit v1.2.3