-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
[457] - Immersive reading view #771
Conversation
- Hiding bars when scrolling down WebView & showing when scrolling up. - Showing bars when device rotates into landscape mode.
17f7f5b
to
5fa9727
Compare
5fa9727
to
ae374b0
Compare
It‘s important to check that his fox has no unwanted side effect on macOS (iPadOS?) |
@TheRealAnt I like that the feature is implemented with so few lines of code |
@TheRealAnt Currently your changes are limited to iOS / iPad OS only, so they have no effect on macOS, which is good. |
- Added WebView to Log. - Added TargetDevice enum to easily check for the current device type.
Model/Utilities/TargetDevice.swift
Outdated
import UIKit | ||
|
||
enum TargetDevice { | ||
case nativeMac | ||
case iPad | ||
case iPhone | ||
case iWatch | ||
|
||
public static var currentDevice: Self { | ||
var currentDeviceModel = UIDevice.current.model | ||
#if targetEnvironment(macCatalyst) | ||
currentDeviceModel = "nativeMac" | ||
#elseif os(watchOS) | ||
currentDeviceModel = "watchOS" | ||
#endif | ||
|
||
if currentDeviceModel.starts(with: "iPhone") { | ||
return .iPhone | ||
} | ||
if currentDeviceModel.starts(with: "iPad") { | ||
return .iPad | ||
} | ||
if currentDeviceModel.starts(with: "watchOS") { | ||
return .iWatch | ||
} | ||
return .nativeMac | ||
} | ||
} |
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.
This won't compile for macOS.
We do not use macCatalyst, and UIKit cannot be imported for macOS.
We do not target watchOS at all, so that is not needed.
I would suggest something like this instead:
import UIKit | |
enum TargetDevice { | |
case nativeMac | |
case iPad | |
case iPhone | |
case iWatch | |
public static var currentDevice: Self { | |
var currentDeviceModel = UIDevice.current.model | |
#if targetEnvironment(macCatalyst) | |
currentDeviceModel = "nativeMac" | |
#elseif os(watchOS) | |
currentDeviceModel = "watchOS" | |
#endif | |
if currentDeviceModel.starts(with: "iPhone") { | |
return .iPhone | |
} | |
if currentDeviceModel.starts(with: "iPad") { | |
return .iPad | |
} | |
if currentDeviceModel.starts(with: "watchOS") { | |
return .iWatch | |
} | |
return .nativeMac | |
} | |
} | |
#if os(iOS) | |
import UIKit | |
#endif | |
enum Device { | |
case mac | |
case iPhone | |
case iPad | |
public static var current: Self { | |
#if os(macOS) | |
mac | |
#else | |
switch UIDevice.current.userInterfaceIdiom { | |
case .pad: return iPad | |
case .phone: return iPhone | |
default: | |
assertionFailure("unrecognised device type: \(UIDevice.current)") | |
return iPhone | |
} | |
#endif | |
} | |
} |
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.
@TheRealAnt, @kelson42 I've updated this PR with a couple of things:
- removed an old "hack" around the page layout, which we no longer need
- made sure we show the bars:
- if the device is rotated (landscape/portrait)
- if the url changes (either by clicking on a link or navigating back and forth by arrows or by dragging from the side of the screen)
- if we scroll to the very top of the screen. This is a bit of a double defence, as scrolling up should also trigger this, but to be on the safe side, as it turned out it is possible to scroll and navigate at the same time
Fixes #457
Demo:
Demo.1.mov