-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New] Generate offline map #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we briefly mentioned, view model could be better for this sample.
I think we may need to jot down the criteria/threshold in the wiki on when to make it a view model, after finish reviewing the recent PRs.
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
offlineMap = output.offlineMap | ||
|
||
// Sets the initial viewpoint of the offline map. | ||
offlineMap?.initialViewpoint = Viewpoint(targetExtent: areaOfInterest.expanded(by: 0.8)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offline-map-tiles.mp4
To other reviewers: There seems to be an API bug for the generated offline map, will need 👀 from other reviewers. When the map is zoomed out with 2 fingers, it sometimes shows a larger extent than the red box. It seems that additional basemap tiles are included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue logged at swift/issues/2008
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems sth is holding up the model when the view disappears/sample quits. When I enter the sample multiple times, it holds multiple instances of the model. I'll need to take another look tomorrow.
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
I have experimented for quite a while and still could not figure out the root cause. 3 samples that uses view models currently:
Set surface placement mode: The view model is released My observation is that the view model in Set surface placement mode sample doesn't have any async task involved. So I'm guessing something is off in the async part of these samples. I'll move on and keep reviewing the other parts of the code. |
I think the root cause of the memory leak may lie within the alert modifier; more specifically, the Also, I was wondering when is the observable object supposed to be released from memory? When I return to the list of samples, the view model is still in memory until I either navigate to the same sample, where it is released and initialized again, or I navigate to a different sample. |
Hmm this is quite 🤯 . Thanks for pointing this out. I'll give it another try on Xcode 14 beta.
This is an expected behavior, but not ideal. IMO It's due to the split screen navigation style. When exit from a sample, the view is not released until a new sample is selected. (think of an iPad) We discussed about this before in the old sample viewer but couldn't figure out a better way. 😕 |
With some workarounds of the build phase bug, I tested it on Xcode 14 and iOS 16, and the models are no longer held. So I'm happy to let it slide for now as an iOS bug 😬 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with the comments above and below. Don't forget to solve merge conflict.
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Cancels the generate offline map job when the view disappears and moves removing the temporary directory into deinit.
Another thing I saw is that the generate offline map job is not cancelled when the view disappears, causing the view model to exist until the task is complete, even if the sample is not being viewed. Ideally the cancellation code would go in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the efforts! 💯
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
.onDisappear { | ||
Task { await model.cancelJob() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, it's implemented in the
onDisappear
modifier, which will cause the download task the cancel when the README viewer is presented while downloading.
When the sample info view is implemented, if the visibility state of that view were passed down through the environment, then a check for that could be added here:
guard !isSampleInfoViewVisible else { return }
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Generate offline map/GenerateOfflineMapView.swift
Outdated
Show resolved
Hide resolved
Button("Generate Offline Map") { | ||
isGeneratingOfflineMap = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That still seems bright to me.
Description
This PR implements
Generate offline map
inMaps
category.URL to README: URL
Linked Issue(s)
common-samples/issues/3624
How To Test
Screenshots
generate-offline-map-demo.mp4
To Discuss