I'm Using UICollectionViewCompositionalLayout with a section provider and I set the NSCollectionLayoutSectionVisibleItemsInvalidationHandler on a particular section.
The NSCollectionLayoutSectionVisibleItemsInvalidationHandler hands back an array of objects conforming to the NSCollectionLayoutVisibleItem protocol which has a name property which always appears to be nil.
I figured there must be a way to use this name property to make it easier to do look up for the NSCollectionLayoutVisibleItem objects I'm actually looking. Is there a way to make this property nonnil?
Does it get set to the UICollectionViewCell's reuse identifier or something (I'm currently using UICollectionViewCellRegistration)?
Is there any documentation on the name property? https://developer.apple.com/documentation/uikit/nscollectionlayoutvisibleitem/3199122-name?language=objc
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
In a SwiftUI source file Xcode displays a window with a Split View. The first split is the source code and the second split is the preview.
My question is, is there a way for me to have the preview take over the entire window width (I want to collapse the source code pane and just look at the preview)?
I can easily collapse the Preview pane by dragging the split to the right to collapse (but it doesn't work in reverse). I also can toggle the preview pane by going to Editor -> Canvas in the Menu bar.
Currently I'm using SwiftUI just to get a live preview of UIKit view controllers so I'm not interested in looking at the SwiftUI source code, though I imagine displaying a full window preview in a separate window would be useful for SwiftUI developers too. You could edit the source code on one monitor and have the preview window on an external display. Is this not possible?
I see WKContentRuleListStore saves compile lists by identifier. It's nice that I don't have to recompile the WKContentRuleListStore on every app launch but is there ever an event where the system discards compiled lists (other than me calling -removeContentRuleListForIdentifier:completionHandler:)?
The reason I ask is should I be writing a version number with my compiled list? If I change the JSON code on an app update do I need to manually remove compiled lists after an app update before recompiling the new JSON?
I see in the documentation that it is possible to hide elements on a page using a CSS selector by setting the action type to css-display-none and then providing a selector.
But this is kind of limited. You have to know every selector for every style sheet ahead of time. It's possible to block loading of a style sheet using a block rule.
"trigger" : {
"load-type" : [
"third-party"
],
"url-filter" : "REGEX_FOR_STYLESHEET_OF_KNOWN_NASTY_CONTENT_PROVIDER",
"resource-type" : [
"style-sheet"
],
"url-filter-is-case-sensitive" : true
},
"action" : {
"type" : "block"
}
Is is my understanding that the above rule will block loading of a stylesheet that matches the url-filter but all elements will still be displayed by WKWebView using the default style provided by the browser. Am I misunderstanding?
Ideally I'd like to be able to set display:none; for every selector in the evil style sheet. I of course can look at the style sheet and make css-display-none rules for every selector manually but that's pretty much impossible to maintain for rule lists with thousands of entires and will break when the author of the nasty stylesheet makes any changes.
Is there a way to accomplish what I'm after using WKContentRuleList?
When trying to compile a rule list via WKContentRuleListStore's -compileContentRuleListForIdentifier:encodedContentRuleList:completionHandler: method I'm getting the following error:
** Rule list compilation failed Too many rules in JSON array.**
The max number of rules allowed in a WKContentRuleList doesn't seem to be documented (or I couldn't find it). Does anyone know what the limit is?
Thanks
I need to prepare an object when the user navigates to a new page in WKWebView and refresh UI. I run a WKUserScript on behalf of the user to do this.
I'm using the readystatechange event listener to detect initial page load. I'm also listening to the visibilitychange event to refresh UI if the DOM is already loaded on a "Go back" or "Go Forward" action.
document.addEventListener('visibilitychange', () => {
//do whatever if the DOM is already loaded and if we are visible.
});
document.addEventListener('readystatechange', (event) =>
{
//do whatever when page is loaded
});
On certain websites however I noticed that neither of these events are being fired when I navigate -goForward: and -goBack:
I'm not sure why. My WKUserScript is in WKContentWorld.defaultClientWorld so it shouldn't be interfering with the javascript of the page. Is there another JS event I'm missing?
I could pick up the changed URL on the native code side but it would be nice to keep this all contained within the WKUserScript as this UI is for the "webview" and the native code shouldn't have to be bothered with having to patch in the additional glue. Is there another DOM event I need to listen to? I tried listening to window's pageshow but that didn't work. Also experimented a bit with the window's popstate event but no luck.
It appears a lot of useful WWDC session videos from previous years have been scrubbed from the developer.apple.com? I cannot find the WWDC session "Customized Loading in WKWebView" from 2017 in the Developer app nor on the developer website.
There are lots of other videos that would be useful to watch, even from years ago. Am I just not looking in the right place?
I'm having a hard time finding samples that clearly explain how to use WKContentRuleList objects. I read that WKContentRuleList use the same format as Safari content blocker extensions however when I try to compile a content blocker from the sample app AdoptingDeclarativeContentBlockingInSafariWebExtensions it complains about missing a "trigger". I get
Error Domain=WKErrorDomain Code=6 "(null)" UserInfo={NSHelpAnchor=Rule list compilation failed: Invalid trigger object.}
When I try to use the rules from the AdoptingDeclarativeContentBlockingInSafariWebExtensions sample project:
[
{
"id": 1,
"priority": 1,
"action": { "type": "block" },
"condition": {"regexFilter": ".*", "resourceTypes": [ "image" ] }
},
{
"id": 2,
"priority": 1,
"action": { "type": "allow" },
"condition": {"regexFilter": "wikipedia", "resourceTypes": [ "image" ] }
}
]
So if WKContentRuleList requires different keys/value pairs than Safari content blockers are those differences documented anywhere? I can't really find any good info on this.
Thanks in advance.
Is there a way to block certain embedded inline javascript elements using WKContentRuleList? For example
<script>
evilJavascriptHere
</script>
The documentation states that you can specify a url-filter but what about inline scripts?
I have a custom pop animation is use with UINavigationController. I provide this via the delegate method
-
-(nullable id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController*)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController*)fromVC
toViewController:(UIViewController*)toVC
And it works except when I push the view controller initially from UISearchController's .searchResultsController. This issue is that when I push on the navigation stack when the UISearchResultsController is displaying the searchResultsController, when I pop back the UIViewControllerContextTransitioning passed to my animator doesn't provide values to account for the search controller displayed over the main view controller and the custom animation doesn't work.
Is there a good way to handle this? Thanks in advance.
So I'm using a custom presentation controller which requires me to specify a transitioningDelegate on the view controller before presenting it like this:
vcToPresent.modalPresentationStyle = UIModalPresentationCustom;
vcToPresent.transitioningDelegate = transitionDelegate;
Now I want to enforce a particular view controller to always use my custom presentation controller. Unfortunately I cannot just override the presentationController getter and return my own custom class; I have to make a transitioning delegate and an additional animator (and my custom presentation controller can animate alongside it). To have a view controller use my own presentation controller I have to do this:
-(void)presentCustomVC
{
MyViewController *vcToPresent = [MyViewController makeViewController];
MyTransitioningDelegate *transitionDelegate = [[MyTransitioningDelegate alloc]init];
vcToPresent.modalPresentationStyle = UIModalPresentationCustom;
vcToPresent.transitioningDelegate = transitionDelegate;
[self presentViewController:vcToPresent animated:YES completion:nil];
}
So I have to copy this transitioningDelegate set up code in every view controller that presents MyViewController. I can make the API look a little better by creating a factory method in MyViewController like this:
+(MyViewController*)makeViewController
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
MyViewController *theVC = [storyboard instantiateInitialViewController];
MyTransitioningDelegate *transDelegate = [[MyTransitioningDelegate alloc]init];
theVC.modalPresentationStyle = UIModalPresentationCustom;
theVC.transitioningDelegate = transDelegate;
return theVC;
}
The problem with that is the transitioningDelegate gets deallocated right away (before the view controller can be presented). The transitioningDelegate property on UIViewController is weak for some reason.
Shouldn't the transitioningDelegate property be declared strong? My custom transitioningDelegate has no strong reference to the presented view controller? If I add a redundant property to MyViewController like this:
@property (nonatomic,strong) MyTransitioningDelegate *strongTransDelegate;
And then do this:
theVC.modalPresentationStyle = UIModalPresentationCustom;
theVC.transitioningDelegate = transDelegate;
theVC.strongTransDelegate = transitionDelegate;
All seems to work well. When the view controller is dismissed the transitioning delegate is deallocated. However I'm assuming the transitioningDelegate property on UIViewController was declared as weak for a reason? I don't want to accidentally create a retain cycle in some unforeseen circumstance. Documentation makes no mention on who should be the "owner" of the transitioning delegate?
I'm using a custom UIPresentationController. I'd like the replicate the behavior of UISheetPresentationController and allow user interaction the presenting view controller when the presented view controller does not cover the entire screen.
I tried this:
-(void)presentationTransitionDidEnd:(BOOL)completed
{
UIView *theView = self.presentingViewController.view;
theView.userInteractionEnabled = YES;
}
But has no effect. Is it possible to achieve this behavior? Thanks in advance
I’m using UISheetPresentationController with a UIViewController.
While the sheet is being resized I’d like to position certain subviews a certain way during the resizing event. For example I may hide some subviews on a smaller detent and unhide them on a larger detent. But while the sheet is being resized in between the small and large detent I’d like to have some subviews placed at certain locations of the view hierarchy.
As far as I can tell the only way to do this is with unreliable hard coded values:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
CGFloat currentHeight = self.view.bounds.size.height;
if (currentHeight <= mediumDetent)
{
[self doLayoutForMediumDetent];
}
else if (currentHeight >= fullSizeDetent)
{
[self doLayoutForFullSizedDetent];
}
else
{
[self doLayoutInBetweenFullAndMediumSheetWithCurrentSize:currentHeight];
}
}
I don't really know for sure the height of the detents. I'm using estimates so this layout code is fragile. For the medium detent the documentation states that it is "A system detent for a sheet that is approximately half the height of the screen, and is inactive in compact height." but on certain devices the medium detent height is not exactly 1/2 the screen height.
Ideally it would be nice to have API like this:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
CGFloat mediumHeight = [self.sheetPresentationController resolvedHeightForDetentWithIdentiier:someID withTraitCollection:self.traitCollection];
CGFloat fullHeight = [self.sheetPresentationController resolvedHeightForDetentWithIdentiier:FullSizeID withTraitCollection:self.traitCollection];
if (self.sheetPresentationController.isInLiveResize)
{
//do whatever during live resize
}
else
{
//do whatever at the current size
}
}
Is there currently a better way to achieve what I'm after?
Edit: Was able to resolve. This thread may be deleted.
I'd like to ensure certain content doesn't overlap UISheetPresentationController's grabber.
In the view controller subclass that is being presented as a sheet via UISheetPresentationController I tried inspecting self.view.safeAreaInset.top hoping that this would account for the UISheetPresentationController's grabber but safeAreaInset.top is 0 unfortunately.
Right now I'm just using a hard coded value but is there API for this I overlooked?