mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-04-10 12:05:50 +00:00
improve state restoration, leverage restoration IDs more
This commit is contained in:
parent
d3db0f74c7
commit
3c459ed7df
5 changed files with 22 additions and 41 deletions
|
|
@ -72,9 +72,12 @@
|
|||
- (EditorViewController *)editorViewController {
|
||||
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
|
||||
UINavigationController *navigationController = splitViewController.viewControllers.firstObject;
|
||||
navigationController = navigationController.viewControllers.lastObject;
|
||||
EditorViewController *editorViewController = (EditorViewController *)navigationController.viewControllers.firstObject;
|
||||
return editorViewController;
|
||||
if (navigationController.viewControllers.count > 1) {
|
||||
navigationController = navigationController.viewControllers.lastObject;
|
||||
EditorViewController *editorViewController = (EditorViewController *)navigationController.viewControllers.firstObject;
|
||||
return editorViewController;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (ModelStore *)newModelStoreWithPath:(NSString *)dbPath {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@
|
|||
<constraint firstAttribute="width" secondItem="VV9-18-i5M" secondAttribute="height" multiplier="1:1" id="vkJ-Ki-XVe"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ydf-ii-P8M">
|
||||
<button opaque="NO" contentMode="scaleToFill" restorationIdentifier="Link Button" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ydf-ii-P8M">
|
||||
<rect key="frame" x="32" y="1" width="116" height="29"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<state key="normal" title="http://samhuri.net">
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
<action selector="tappedLinkButton:" destination="JEX-9P-axG" eventType="touchUpInside" id="2Wx-9Z-i8K"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="81X-Pe-PFV">
|
||||
<button opaque="NO" contentMode="scaleAspectFit" restorationIdentifier="Remove Link Button" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="81X-Pe-PFV">
|
||||
<rect key="frame" x="565" y="0.0" width="30" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" secondItem="81X-Pe-PFV" secondAttribute="height" multiplier="1:1" id="iW2-b5-VdB"/>
|
||||
|
|
@ -117,7 +117,7 @@
|
|||
</mask>
|
||||
</variation>
|
||||
</view>
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wrG-1y-ZY3">
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" restorationIdentifier="Editor Text View" alwaysBounceVertical="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wrG-1y-ZY3">
|
||||
<rect key="frame" x="0.0" y="30" width="600" height="462"/>
|
||||
<color key="backgroundColor" red="0.26666666666666666" green="0.26666666666666666" blue="0.26666666666666666" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<string key="text">The latest technology I've been learning is Palm's SDK for webOS,
|
||||
|
|
@ -210,7 +210,7 @@ wanted with as little input and thought as possible.</string>
|
|||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="G2v-XU-V16">
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="Text Field" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="G2v-XU-V16">
|
||||
<rect key="frame" x="16" y="285" width="568" height="30"/>
|
||||
<color key="backgroundColor" red="0.2666666667" green="0.2666666667" blue="0.2666666667" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<color key="textColor" red="0.96862745100000003" green="0.96862745100000003" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
|
|
@ -247,11 +247,11 @@ wanted with as little input and thought as possible.</string>
|
|||
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<webView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0n2-Ma-NtP">
|
||||
<webView contentMode="scaleToFill" restorationIdentifier="Web View" translatesAutoresizingMaskIntoConstraints="NO" id="0n2-Ma-NtP">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="ixd-IL-hNy" id="UhD-wi-jtK"/>
|
||||
<outlet property="delegate" destination="ixd-IL-hNy" id="Alk-Fw-YWo"/>
|
||||
</connections>
|
||||
</webView>
|
||||
</subviews>
|
||||
|
|
@ -294,7 +294,7 @@ wanted with as little input and thought as possible.</string>
|
|||
<scene sceneID="smW-Zh-WAh">
|
||||
<objects>
|
||||
<tableViewController storyboardIdentifier="Posts View Controller" title="Posts" useStoryboardIdentifierAsRestorationIdentifier="YES" id="7bK-jq-Zjz" customClass="PostsViewController" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="singleLineEtched" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="r7i-6Z-zg0">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="Posts Table View" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="singleLineEtched" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="r7i-6Z-zg0">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="0.66666666669999997" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
|
|
|
|||
|
|
@ -212,13 +212,11 @@
|
|||
|
||||
static NSString *const StateRestorationPostKey = @"post";
|
||||
static NSString *const StateRestorationModifiedPostKey = @"modifiedPost";
|
||||
static NSString *const StateRestorationTextViewContentOffsetKey = @"textView.contentOffset";
|
||||
|
||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
NSLog(@"%@ encode restorable state with coder %@", self, coder);
|
||||
[coder encodeObject:self.post forKey:StateRestorationPostKey];
|
||||
[coder encodeObject:self.modifiedPost forKey:StateRestorationModifiedPostKey];
|
||||
[coder encodeCGPoint:self.textView.contentOffset forKey:StateRestorationTextViewContentOffsetKey];
|
||||
[super encodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +224,6 @@ static NSString *const StateRestorationTextViewContentOffsetKey = @"textView.con
|
|||
NSLog(@"%@ decode restorable state with coder %@", self, coder);
|
||||
self.post = [coder decodeObjectForKey:StateRestorationPostKey];
|
||||
self.modifiedPost = [coder decodeObjectForKey:StateRestorationModifiedPostKey];
|
||||
self.textView.contentOffset = [coder decodeCGPointForKey:StateRestorationTextViewContentOffsetKey];
|
||||
[super decodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -249,14 +249,12 @@ static const NSUInteger SectionPublished = 1;
|
|||
static NSString *const StateRestorationPostCollectionsKey = @"postCollections";
|
||||
static NSString *const StateRestorationBlogStatusDateKey = @"blogStatusDate";
|
||||
static NSString *const StateRestorationBlogStatusTextKey = @"blogStatusText";
|
||||
static NSString *const StateRestorationTabelViewContentOffsetKey = @"tableView.contentOffset";
|
||||
|
||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
NSLog(@"%@ encode restorable state with coder %@", self, coder);
|
||||
[coder encodeObject:self.postCollections forKey:StateRestorationPostCollectionsKey];
|
||||
[coder encodeObject:self.blogStatusDate forKey:StateRestorationBlogStatusDateKey];
|
||||
[coder encodeObject:self.blogStatusText forKey:StateRestorationBlogStatusTextKey];
|
||||
[coder encodeCGPoint:self.tableView.contentOffset forKey:StateRestorationTabelViewContentOffsetKey];
|
||||
[super encodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +263,6 @@ static NSString *const StateRestorationTabelViewContentOffsetKey = @"tableView.c
|
|||
self.postCollections = [coder decodeObjectForKey:StateRestorationPostCollectionsKey];
|
||||
self.blogStatusDate = [coder decodeObjectForKey:StateRestorationBlogStatusDateKey];
|
||||
self.blogStatusText = [coder decodeObjectForKey:StateRestorationBlogStatusTextKey];
|
||||
self.tableView.contentOffset = [coder decodeCGPointForKey:StateRestorationTabelViewContentOffsetKey];
|
||||
[super decodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@
|
|||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
// UIWebView restores its request so we just have to reload it
|
||||
if (!self.initialRequest && self.webView.request) {
|
||||
[self.webView reload];
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.initialRequest) {
|
||||
if (self.promise) {
|
||||
__weak __typeof__(self) welf = self;
|
||||
|
|
@ -29,10 +35,10 @@
|
|||
__typeof__(self) self = welf;
|
||||
self.promise = nil;
|
||||
});
|
||||
return;
|
||||
}
|
||||
else {
|
||||
[self.webView loadRequest:self.initialRequest];
|
||||
}
|
||||
[self.webView loadRequest:self.initialRequest];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,28 +47,6 @@
|
|||
[self.webView loadHTMLString:@"<!doctype html><html><head><title></title></head><body></body></html>" baseURL:nil];
|
||||
}
|
||||
|
||||
#pragma mark - State restoration
|
||||
|
||||
static NSString *const StateRestorationInitialRequestKey = @"initialRequest";
|
||||
static NSString *const StateRestorationWebViewRequestURLKey = @"webView.request.URL";
|
||||
|
||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:self.initialRequest forKey:StateRestorationInitialRequestKey];
|
||||
[coder encodeObject:self.webView.request.URL forKey:StateRestorationWebViewRequestURLKey];
|
||||
[super encodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
NSURL *url = [coder decodeObjectForKey:StateRestorationWebViewRequestURLKey];
|
||||
if (url) {
|
||||
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
|
||||
}
|
||||
else {
|
||||
self.initialRequest = [coder decodeObjectForKey:StateRestorationInitialRequestKey];
|
||||
}
|
||||
[super decodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
#pragma mark - UIWebViewDelegate methods
|
||||
|
||||
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
||||
|
|
|
|||
Loading…
Reference in a new issue