I am trying to display a list of SwiftUI using UICollectionView, what I did is: using UICollectionViewCell to host the UIHostingController
when the cell willDisplay, I added the UIHostingController to parent view controller
remove it from parent controller when cell didEndDisplay
I notice sometimes, swiftUI only shows half or less half height of cell's height, when I scroll a cell outside screen back to screen, it made me feel the swiftUI is not rendered proper when it's outside screen.
code to host the UIHostingController:
class MyCell: UICollectionViewCell {
		private lazy var widgetHostingVC: UIHostingController<AnyView> = {
let vc = UIHostingController(rootView: AnyView(Text("")))
return vc
}()
		/* BTW, widgetHostingVC's view is added to contentView during init, with constraints edge to edge */
}
code to pass SwiftUIView to cell, called when cellForItemAt:indexPath::
func config(_ swiftUIView: AnyView) {
		self.widgetHostingVC.rootView = swiftUIView
}
code to add widgetHostingVC to parentVC, called when cell willDisplay:
func addViewControllerToParentVC(_ parentVC: UIViewController) {
		parentVC.addChild(self.widgetHostingVC)
		self.widgetHostingVC.didMove(toParent: parentVC)
		self.contentView.addSubview(self.widgetHostingVC.view)
		// setup constraints
}
code to remove widgetHostingVC from parentVC, call when cell didEndDisplaying:
func removeViewControllerFromParentVC() {
		self.widgetHostingVC.removeFromParent()
}
Anyone know what is the problem cause the swiftUI not render with correct height?
Post
Replies
Boosts
Views
Activity
I have read Widget Timelines With Clock-Based App - https://developer.apple.com/forums/thread/650293,
Keeping a Widget Up To Date - https://developer.apple.com/documentation/widgetkit/keeping-a-widget-up-to-date
WidgetKit won't request a new timeline at the end - https://developer.apple.com/forums/thread/653265
I learnt that
WidgetKit Extension is not alive whenever the widget is visible
Updating every minute is far too aggressive. Widgets have a limited number of updates and if you were to try to update every minute, you'll quickly run out of updates. But from my observation to those popular widget apps in the app store, they all manage to update widget every single minute precisely, not only the digital clock but also Analog clock.
If widget is a static snapshot, not alive, we are not allowed to provide a timer, and we also have limit timeline entry to update, why these apps are working?
Is there anything I missed reading, or is there anything missing from document?
I am trying to show a large text on Widget, larger than .largeTitle, and I notice when the text size exceed 48, the widget shows blank screen, and it come back when I change the text size to 47.
struct TestView: View {
var body: some View {
				Text("Hi").font(.system(size: 48))
		}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
				TestView()
					.previewContext(WidgetPreviewContext(family: .systemSmall))
		}
}
The Text seems stop expending itself. Is this the limitation or I missed something?
When user picked an image from photo library, using UIImagePickerController, there is a compressed version of the same image is saved at tmp folder as well, from my test, the compressed image becomes 800 KB from the original 5 MB photo.
I want to have more control about those images under tmp folder, so I like to know: Do we have option to turn off saving a compressed image to tmp folder?
Do we have option to set compression rate?
Do we have option to change the location fromtmp folder to some other place?
I am displaying 3 rows in medium size widget like below:
row 1
row 2
row 3
my view structure is here:
VStack {
		ForEach(records, id: \.id) { item in
				ZStack {
						// some views
				}
				.widgetURL(URL(string: "wig://\(item.id)"))
		}
		Divider()
}
It seems the widget URL for first and second items are override by the the third item, all deep link will open third item's content.
what is the proper way to add deep link for views generated from ForEach?
My mac is using Catalina, I was following the link installing macOS Beta on a separate APFS volume - https://support.apple.com/en-us/HT208891 to install Big Sur Beta. After installation completed, I switch back to Catalina, I found the developer app installed on Catalina won't work, it crashes immediate when I open it.
I tried to delete the volume that installed Big Sur Beta, but it's not working, I am still not able to open developer app. Further more, on Catalina OS Volume, there are two new volume was created: Volume with name update appears on desktop, I have no idea what it is.
Volume with name disk1s7 appears on disk untilites, I cannot erase it, I cannot delete it.
The question is, how to completed remove beta OS from separate APFS volume with the volume update and disk1s7?