From 38a7f6226b508d52ec4a0bd286e40642d95f684d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=9F=E3=81=A4=E3=81=9D=E3=82=99=E3=81=86?= Date: Mon, 24 May 2021 13:20:55 +0800 Subject: [PATCH] fix: iPad reading width --- EhPanda/View/Content/ContentView.swift | 27 +++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/EhPanda/View/Content/ContentView.swift b/EhPanda/View/Content/ContentView.swift index 358fc706..d9163ff4 100644 --- a/EhPanda/View/Content/ContentView.swift +++ b/EhPanda/View/Content/ContentView.swift @@ -67,7 +67,10 @@ struct ContentView: View, StoreAccessor { retryLimit: setting.contentRetryLimit, onSuccessAction: onWebImageSuccess ) - .frame(height: calImageHeight(item.tag)) + .frame( + width: absoluteScreenW, + height: calImageHeight(item.tag) + ) .onAppear { onWebImageAppear(item) } @@ -121,7 +124,7 @@ struct ContentView: View, StoreAccessor { for: Notification.Name("DetailViewOnDisappear") ) ) { _ in - onReceiveDetailViewOnDisappearNotification() + onDetailViewDisappear() } .onReceive( NotificationCenter.default.publisher( @@ -137,6 +140,13 @@ struct ContentView: View, StoreAccessor { ) { _ in onResignActive() } + .onReceive( + NotificationCenter.default.publisher( + for: NSNotification.Name("AppWidthDidChange") + ) + ) { _ in + onWidthChange() + } .onAppear(perform: onAppear) .onDisappear(perform: onDisappear) .navigationBarBackButtonHidden(true) @@ -175,9 +185,16 @@ private extension ContentView { saveAspectBox() saveReadingProgress() } - func onReceiveDetailViewOnDisappearNotification() { + func onDetailViewDisappear() { toggleNavBarHiddenIfNeeded() } + func onWidthChange() { + DispatchQueue.main.async { + setOffset(.zero) + setScale(1.1) + setScale(1) + } + } func onLazyVStackAppear(_ proxy: ScrollViewProxy) { if let tag = mangaDetail?.readingProgress { proxy.scrollTo(tag) @@ -217,7 +234,7 @@ private extension ContentView { // MARK: ReadingProgress func calImageHeight(_ tag: Int) -> CGFloat { if let aspect = aspectBox[tag] { - return screenW * aspect + return absoluteScreenW * aspect } else { return screenH * contentHScale } @@ -369,7 +386,7 @@ private struct ImageContainer: View { percentage: percentage ) .frame( - width: screenW, + width: absoluteScreenW, height: screenH * contentHScale ) }