Brion VIBBER has submitted this change and it was merged. Change subject: Prevent jitter when loading lead section on slow connection. ......................................................................
Prevent jitter when loading lead section on slow connection. Sometimes lead section content appeared to start halfway down the screen when using slow connection. Was caused by bottom scroll margin only being added after non lead sections had completely loaded and how this caused the code which limits vertical scrolling to get confused. Solved by adding bottom margin - and last modified by and page history footer - to end of lead section as soon as it loads, and then injecting the non lead section content above this footer stuff after it is retrieved. Also added a couple of nil crash prevention checks. Change-Id: I384896a8f2db25692b13794b970a199fba6d8089 --- M wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m M wikipedia/View Controllers/WebView/WebViewController.m M wikipedia/assets/bundle.js M www/js/listeners.js 4 files changed, 65 insertions(+), 6 deletions(-) Approvals: Brion VIBBER: Verified; Looks good to me, approved diff --git a/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m b/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m index d326973..06ddbfe 100644 --- a/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m +++ b/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m @@ -348,9 +348,11 @@ NSManagedObjectID *currentArticleId = [articleDataContext_.mainContext getArticleIDForTitle: [SessionSingleton sharedInstance].currentArticleTitle domain: [SessionSingleton sharedInstance].currentArticleDomain]; - Article *article = (Article *)[articleDataContext_.mainContext objectWithID:currentArticleId]; - if (article && (article.saved.count == 1)){ - result = YES; + if (currentArticleId) { + Article *article = (Article *)[articleDataContext_.mainContext objectWithID:currentArticleId]; + if (article && (article.saved.count == 1)){ + result = YES; + } } }]; return result; diff --git a/wikipedia/View Controllers/WebView/WebViewController.m b/wikipedia/View Controllers/WebView/WebViewController.m index 5989937..c84c0c0 100644 --- a/wikipedia/View Controllers/WebView/WebViewController.m +++ b/wikipedia/View Controllers/WebView/WebViewController.m @@ -1073,7 +1073,7 @@ domain: [SessionSingleton sharedInstance].currentArticleDomain]; if (!articleID) return; Article *article = (Article *)[articleDataContext_.mainContext objectWithID:articleID]; - if (!article) return; + if (!article || !article.title || !article.domain) return; SavedPagesFunnel *funnel = [[SavedPagesFunnel alloc] init]; if (article.saved.count == 0) { @@ -1901,8 +1901,11 @@ } - if ((mode != DISPLAY_LEAD_SECTION)) { + if (mode != DISPLAY_APPEND_NON_LEAD_SECTIONS) { if (![[SessionSingleton sharedInstance] isCurrentArticleMain]) { + if (mode == DISPLAY_LEAD_SECTION) { + [sectionTextArray addObject: [NSString stringWithFormat:@"<div id='nonLeadSectionsInjectionPoint' style='margin-top:2em;margin-bottom:2em;'>%@</div>", MWLocalizedString(@"search-loading-section-remaining", nil)]]; + } [sectionTextArray addObject: [self renderFooterDivider]]; [sectionTextArray addObject: [self renderLastModified:lastModified by:lastModifiedBy]]; [sectionTextArray addObject: [self renderLanguageButtonForCount: langCount.integerValue]]; @@ -1918,6 +1921,18 @@ // Join article sections text NSString *joint = @""; //@"<div style=\"background-color:#ffffff;height:55px;\"></div>"; NSString *htmlStr = [sectionTextArray componentsJoinedByString:joint]; + + // If any of these are nil, the bridge "sendMessage:" calls will crash! So catch 'em here. + BOOL safeToCrossBridge = (languageInfo.code && languageInfo.dir && uidir && htmlStr); + if (!safeToCrossBridge) { + NSLog(@"\n\nUnsafe to cross JS bridge!"); + NSLog(@"\tlanguageInfo.code = %@", languageInfo.code); + NSLog(@"\tlanguageInfo.dir = %@", languageInfo.dir); + NSLog(@"\tuidir = %@", uidir); + NSLog(@"\thtmlStr is nil = %d\n\n", (htmlStr == nil)); + //TODO: output "could not load page" alert and/or show last page? + return; + } // NSLog(@"languageInfo = %@", languageInfo.code); // Display all sections @@ -1928,7 +1943,11 @@ @"uidir": uidir }]; - [self.bridge sendMessage:@"append" withPayload:@{@"html": htmlStr}]; + if (mode != DISPLAY_APPEND_NON_LEAD_SECTIONS) { + [self.bridge sendMessage:@"append" withPayload:@{@"html": htmlStr}]; + }else{ + [self.bridge sendMessage:@"injectNonLeadSections" withPayload:@{@"html": htmlStr}]; + } // Note: we set the scroll position later, after the size has been calculated if (!self.editable) { diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js index efc8924..eb6aa77 100644 --- a/wikipedia/assets/bundle.js +++ b/wikipedia/assets/bundle.js @@ -140,6 +140,25 @@ content.appendChild(newcontent); }); +bridge.registerListener( "injectNonLeadSections", function( payload ) { + // Append html without losing existing event handlers + // From: http://stackoverflow.com/a/595825 + + var newcontent = document.createElement('div'); + newcontent.innerHTML = payload.html; + + //transformer.transform( "relocateInfobox", newcontent ); + transformer.transform( "hideRedlinks", newcontent ); + transformer.transform( "disableFilePageEdit", newcontent ); + transformer.transform( "hideAudioTags", newcontent ); + transformer.transform( "overflowWideTables", newcontent ); + + var content = document.getElementById("nonLeadSectionsInjectionPoint"); + // Ensure we've done transforms *before* injecting the new content. + // Otherwise the web view dom will thrash. + content.parentNode.replaceChild(newcontent, content); +}); + bridge.registerListener( "remove", function( payload ) { document.getElementById( "content" ).removeChild(document.getElementById(payload.element)); }); diff --git a/www/js/listeners.js b/www/js/listeners.js index c145902..3660c2c 100644 --- a/www/js/listeners.js +++ b/www/js/listeners.js @@ -44,6 +44,25 @@ content.appendChild(newcontent); }); +bridge.registerListener( "injectNonLeadSections", function( payload ) { + // Append html without losing existing event handlers + // From: http://stackoverflow.com/a/595825 + + var newcontent = document.createElement('div'); + newcontent.innerHTML = payload.html; + + //transformer.transform( "relocateInfobox", newcontent ); + transformer.transform( "hideRedlinks", newcontent ); + transformer.transform( "disableFilePageEdit", newcontent ); + transformer.transform( "hideAudioTags", newcontent ); + transformer.transform( "overflowWideTables", newcontent ); + + var content = document.getElementById("nonLeadSectionsInjectionPoint"); + // Ensure we've done transforms *before* injecting the new content. + // Otherwise the web view dom will thrash. + content.parentNode.replaceChild(newcontent, content); +}); + bridge.registerListener( "remove", function( payload ) { document.getElementById( "content" ).removeChild(document.getElementById(payload.element)); }); -- To view, visit https://gerrit.wikimedia.org/r/164490 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I384896a8f2db25692b13794b970a199fba6d8089 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits