mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Browser improvements
This commit is contained in:
parent
2eeb3be2b2
commit
e0f95989d4
@ -13,17 +13,20 @@ final class BrowserAddressListComponent: Component {
|
||||
let context: AccountContext
|
||||
let theme: PresentationTheme
|
||||
let strings: PresentationStrings
|
||||
let insets: UIEdgeInsets
|
||||
let navigateTo: (String) -> Void
|
||||
|
||||
init(
|
||||
context: AccountContext,
|
||||
theme: PresentationTheme,
|
||||
strings: PresentationStrings,
|
||||
insets: UIEdgeInsets,
|
||||
navigateTo: @escaping (String) -> Void
|
||||
) {
|
||||
self.context = context
|
||||
self.theme = theme
|
||||
self.strings = strings
|
||||
self.insets = insets
|
||||
self.navigateTo = navigateTo
|
||||
}
|
||||
|
||||
@ -37,6 +40,9 @@ final class BrowserAddressListComponent: Component {
|
||||
if lhs.strings !== rhs.strings {
|
||||
return false
|
||||
}
|
||||
if lhs.insets != rhs.insets {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -211,6 +217,7 @@ final class BrowserAddressListComponent: Component {
|
||||
theme: component.theme,
|
||||
style: .plain,
|
||||
title: sectionTitle,
|
||||
insets: component.insets,
|
||||
actionTitle: section.id == 0 ? "Clear" : nil,
|
||||
action: { [weak self] in
|
||||
if let self, let component = self.component {
|
||||
@ -292,6 +299,7 @@ final class BrowserAddressListComponent: Component {
|
||||
webPage: webPage!,
|
||||
message: itemMessage,
|
||||
hasNext: true,
|
||||
insets: component.insets,
|
||||
action: {
|
||||
if let url = webPage?.content.url {
|
||||
navigateTo(url)
|
||||
@ -393,6 +401,7 @@ final class BrowserAddressListComponent: Component {
|
||||
webPage: TelegramMediaWebpage(webpageId: EngineMedia.Id(namespace: 0, id: 0), content: .Loaded(TelegramMediaWebpageLoadedContent(url: "https://telegram.org", displayUrl: "https://telegram.org", hash: 0, type: nil, websiteName: "Telegram", title: "Telegram Telegram", text: "Telegram", embedUrl: nil, embedType: nil, embedSize: nil, duration: nil, author: nil, isMediaLargeByDefault: nil, image: nil, file: nil, story: nil, attributes: [], instantPage: nil))),
|
||||
message: nil,
|
||||
hasNext: true,
|
||||
insets: .zero,
|
||||
action: {}
|
||||
)),
|
||||
environment: {},
|
||||
|
@ -16,6 +16,7 @@ final class BrowserAddressListItemComponent: Component {
|
||||
let webPage: TelegramMediaWebpage
|
||||
var message: Message?
|
||||
let hasNext: Bool
|
||||
let insets: UIEdgeInsets
|
||||
let action: () -> Void
|
||||
|
||||
init(
|
||||
@ -24,6 +25,7 @@ final class BrowserAddressListItemComponent: Component {
|
||||
webPage: TelegramMediaWebpage,
|
||||
message: Message?,
|
||||
hasNext: Bool,
|
||||
insets: UIEdgeInsets,
|
||||
action: @escaping () -> Void
|
||||
) {
|
||||
self.context = context
|
||||
@ -31,6 +33,7 @@ final class BrowserAddressListItemComponent: Component {
|
||||
self.webPage = webPage
|
||||
self.message = message
|
||||
self.hasNext = hasNext
|
||||
self.insets = insets
|
||||
self.action = action
|
||||
}
|
||||
|
||||
@ -44,6 +47,9 @@ final class BrowserAddressListItemComponent: Component {
|
||||
if lhs.hasNext != rhs.hasNext {
|
||||
return false
|
||||
}
|
||||
if lhs.insets != rhs.insets {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -92,7 +98,7 @@ final class BrowserAddressListItemComponent: Component {
|
||||
|
||||
let iconSize = CGSize(width: 40.0, height: 40.0)
|
||||
let height: CGFloat = 60.0
|
||||
let leftInset: CGFloat = 11.0 + iconSize.width + 11.0
|
||||
let leftInset: CGFloat = component.insets.left + 11.0 + iconSize.width + 11.0
|
||||
let rightInset: CGFloat = 16.0
|
||||
let titleSpacing: CGFloat = 2.0
|
||||
|
||||
@ -181,7 +187,7 @@ final class BrowserAddressListItemComponent: Component {
|
||||
}
|
||||
|
||||
|
||||
let iconFrame = CGRect(origin: CGPoint(x: 11.0, y: floorToScreenPixels((height - iconSize.height) / 2.0)), size: iconSize)
|
||||
let iconFrame = CGRect(origin: CGPoint(x: 11.0 + component.insets.left, y: floorToScreenPixels((height - iconSize.height) / 2.0)), size: iconSize)
|
||||
|
||||
let iconImageLayout = self.icon.asyncLayout()
|
||||
var iconImageApply: (() -> Void)?
|
||||
|
@ -188,7 +188,7 @@ protocol BrowserContent: UIView {
|
||||
|
||||
func addToRecentlyVisited()
|
||||
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, transition: ComponentTransition)
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, transition: ComponentTransition)
|
||||
|
||||
func makeContentSnapshotView() -> UIView?
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ final class BrowserDocumentContent: UIView, BrowserContent, WKNavigationDelegate
|
||||
self.webView.underPageBackgroundColor = presentationData.theme.list.plainBackgroundColor
|
||||
}
|
||||
if let (size, insets, fullInsets) = self.validLayout {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, transition: .immediate)
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, safeInsets: .zero, transition: .immediate)
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ final class BrowserDocumentContent: UIView, BrowserContent, WKNavigationDelegate
|
||||
}
|
||||
|
||||
private var validLayout: (CGSize, UIEdgeInsets, UIEdgeInsets)?
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
self.validLayout = (size, insets, fullInsets)
|
||||
|
||||
self.previousScrollingOffset = ScrollingOffsetState(value: self.webView.scrollView.contentOffset.y, isDraggingOrDecelerating: self.webView.scrollView.isDragging || self.webView.scrollView.isDecelerating)
|
||||
|
@ -301,7 +301,7 @@ final class BrowserInstantPageContent: UIView, BrowserContent, UIScrollViewDeleg
|
||||
guard let (size, insets, fullInsets) = self.containerLayout else {
|
||||
return
|
||||
}
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, transition: transition)
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, safeInsets: .zero, transition: transition)
|
||||
}
|
||||
|
||||
func reload() {
|
||||
@ -375,11 +375,11 @@ final class BrowserInstantPageContent: UIView, BrowserContent, UIScrollViewDeleg
|
||||
scrollView.setContentOffset(CGPoint(x: 0.0, y: -scrollView.contentInset.top), animated: true)
|
||||
}
|
||||
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, transition: transition.containedViewLayoutTransition)
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, safeInsets: safeInsets, transition: transition.containedViewLayoutTransition)
|
||||
}
|
||||
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, transition: ContainedViewLayoutTransition) {
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, transition: ContainedViewLayoutTransition) {
|
||||
self.containerLayout = (size, insets, fullInsets)
|
||||
|
||||
var updateVisibleItems = false
|
||||
|
@ -111,7 +111,7 @@ final class BrowserPdfContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
||||
self.backgroundColor = presentationData.theme.list.plainBackgroundColor
|
||||
}
|
||||
if let (size, insets, fullInsets) = self.validLayout {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, transition: .immediate)
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, safeInsets: .zero, transition: .immediate)
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ final class BrowserPdfContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
||||
}
|
||||
|
||||
private var validLayout: (CGSize, UIEdgeInsets, UIEdgeInsets)?
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
self.validLayout = (size, insets, fullInsets)
|
||||
|
||||
self.previousScrollingOffset = ScrollingOffsetState(value: self.scrollView.contentOffset.y, isDraggingOrDecelerating: self.scrollView.isDragging || self.scrollView.isDecelerating)
|
||||
|
@ -261,6 +261,7 @@ private final class BrowserScreenComponent: CombinedComponent {
|
||||
context: context.component.context,
|
||||
theme: environment.theme,
|
||||
strings: environment.strings,
|
||||
insets: UIEdgeInsets(top: 0.0, left: environment.safeInsets.left, bottom: 0.0, right: environment.safeInsets.right),
|
||||
navigateTo: { url in
|
||||
performAction.invoke(.navigateTo(url))
|
||||
}
|
||||
@ -1370,8 +1371,8 @@ private final class BrowserContentComponent: Component {
|
||||
let bottomInset = (49.0 + component.insets.bottom) * (1.0 - component.scrollingPanelOffsetFraction)
|
||||
let insets = UIEdgeInsets(top: topInset, left: component.insets.left, bottom: bottomInset, right: component.insets.right)
|
||||
let fullInsets = UIEdgeInsets(top: component.insets.top + component.navigationBarHeight, left: component.insets.left, bottom: 49.0 + component.insets.bottom, right: component.insets.right)
|
||||
|
||||
component.content.updateLayout(size: availableSize, insets: insets, fullInsets: fullInsets, transition: transition)
|
||||
|
||||
component.content.updateLayout(size: availableSize, insets: insets, fullInsets: fullInsets, safeInsets: component.insets, transition: transition)
|
||||
transition.setFrame(view: component.content, frame: CGRect(origin: .zero, size: availableSize))
|
||||
|
||||
return availableSize
|
||||
|
@ -117,11 +117,23 @@ private final class TonSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
final class WebView: WKWebView {
|
||||
var customBottomInset: CGFloat = 0.0 {
|
||||
didSet {
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
}
|
||||
|
||||
override var safeAreaInsets: UIEdgeInsets {
|
||||
return UIEdgeInsets(top: 0.0, left: 0.0, bottom: self.customBottomInset, right: 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKUIDelegate, UIScrollViewDelegate {
|
||||
private let context: AccountContext
|
||||
private var presentationData: PresentationData
|
||||
|
||||
let webView: WKWebView
|
||||
let webView: WebView
|
||||
|
||||
private let errorView: ComponentHostView<Empty>
|
||||
private var currentError: Error?
|
||||
@ -170,7 +182,7 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
||||
configuration.mediaPlaybackRequiresUserAction = false
|
||||
}
|
||||
|
||||
self.webView = WKWebView(frame: CGRect(), configuration: configuration)
|
||||
self.webView = WebView(frame: CGRect(), configuration: configuration)
|
||||
self.webView.allowsLinkPreview = true
|
||||
|
||||
if #available(iOS 11.0, *) {
|
||||
@ -245,8 +257,8 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
||||
self.backgroundColor = presentationData.theme.list.plainBackgroundColor
|
||||
self.webView.underPageBackgroundColor = presentationData.theme.list.plainBackgroundColor
|
||||
}
|
||||
if let (size, insets, fullInsets) = self.validLayout {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, transition: .immediate)
|
||||
if let (size, insets, fullInsets, safeInsets) = self.validLayout {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, safeInsets: safeInsets, transition: .immediate)
|
||||
}
|
||||
}
|
||||
|
||||
@ -434,13 +446,13 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
||||
self.webView.scrollView.setContentOffset(CGPoint(x: 0.0, y: -self.webView.scrollView.contentInset.top), animated: true)
|
||||
}
|
||||
|
||||
private var validLayout: (CGSize, UIEdgeInsets, UIEdgeInsets)?
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
self.validLayout = (size, insets, fullInsets)
|
||||
private var validLayout: (CGSize, UIEdgeInsets, UIEdgeInsets, UIEdgeInsets)?
|
||||
func updateLayout(size: CGSize, insets: UIEdgeInsets, fullInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, transition: ComponentTransition) {
|
||||
self.validLayout = (size, insets, fullInsets, safeInsets)
|
||||
|
||||
self.previousScrollingOffset = ScrollingOffsetState(value: self.webView.scrollView.contentOffset.y, isDraggingOrDecelerating: self.webView.scrollView.isDragging || self.webView.scrollView.isDecelerating)
|
||||
|
||||
let webViewFrame = CGRect(origin: CGPoint(x: insets.left, y: insets.top), size: CGSize(width: size.width - insets.left - insets.right, height: size.height - insets.top - fullInsets.bottom))
|
||||
let webViewFrame = CGRect(origin: CGPoint(x: insets.left, y: insets.top), size: CGSize(width: size.width - insets.left - insets.right, height: size.height - insets.top))
|
||||
var refresh = false
|
||||
if self.webView.frame.width > 0 && webViewFrame.width != self.webView.frame.width {
|
||||
refresh = true
|
||||
@ -451,6 +463,9 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
||||
self.webView.reloadInputViews()
|
||||
}
|
||||
|
||||
self.webView.scrollView.contentInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: fullInsets.bottom, right: 0.0)
|
||||
self.webView.customBottomInset = max(insets.bottom, safeInsets.bottom)
|
||||
// self.webView.scrollView.contentInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 34.0, right: 0.0)
|
||||
self.webView.scrollView.scrollIndicatorInsets = UIEdgeInsets(top: 0.0, left: -insets.left, bottom: 0.0, right: -insets.right)
|
||||
self.webView.scrollView.horizontalScrollIndicatorInsets = UIEdgeInsets(top: 0.0, left: -insets.left, bottom: 0.0, right: -insets.right)
|
||||
|
||||
@ -646,8 +661,8 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
||||
} else {
|
||||
self.currentError = nil
|
||||
}
|
||||
if let (size, insets, fullInsets) = self.validLayout {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, transition: .immediate)
|
||||
if let (size, insets, fullInsets, safeInsets) = self.validLayout {
|
||||
self.updateLayout(size: size, insets: insets, fullInsets: fullInsets, safeInsets: safeInsets, transition: .immediate)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ final class SectionHeaderComponent: Component {
|
||||
let theme: PresentationTheme
|
||||
let style: Style
|
||||
let title: String
|
||||
let insets: UIEdgeInsets
|
||||
let actionTitle: String?
|
||||
let action: (() -> Void)?
|
||||
|
||||
@ -20,12 +21,14 @@ final class SectionHeaderComponent: Component {
|
||||
theme: PresentationTheme,
|
||||
style: Style,
|
||||
title: String,
|
||||
insets: UIEdgeInsets,
|
||||
actionTitle: String?,
|
||||
action: (() -> Void)?
|
||||
) {
|
||||
self.theme = theme
|
||||
self.style = style
|
||||
self.title = title
|
||||
self.insets = insets
|
||||
self.actionTitle = actionTitle
|
||||
self.action = action
|
||||
}
|
||||
@ -40,6 +43,9 @@ final class SectionHeaderComponent: Component {
|
||||
if lhs.title != rhs.title {
|
||||
return false
|
||||
}
|
||||
if lhs.insets != rhs.insets {
|
||||
return false
|
||||
}
|
||||
if lhs.actionTitle != rhs.actionTitle {
|
||||
return false
|
||||
}
|
||||
@ -73,7 +79,7 @@ final class SectionHeaderComponent: Component {
|
||||
self.state = state
|
||||
|
||||
let height: CGFloat = 28.0
|
||||
let leftInset: CGFloat = 16.0
|
||||
let leftInset: CGFloat = 16.0 + component.insets.left
|
||||
let rightInset: CGFloat = 0.0
|
||||
|
||||
let previousTitleFrame = self.title.view?.frame
|
||||
|
Loading…
x
Reference in New Issue
Block a user