Comments (7)
Just wanted to thank you again! I managed to make it work and learned a lot in the process!
from swiftui-image-viewer.
Hey there, this is most likely due to an issue due of where you place the image viewer. The image viewer is made to be an overlay for the view that it is placed on.
The following code reproduces the issue you are having, where the image viewer does not cover the tab bar:
struct ContentView: View {
var body: some View {
TabView {
Text("Hey")
.tabItem {
Image(systemName: "list.dash")
Text("Menu")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(ImageViewer(image: .constant(Image(uiImage: UIImage(named: "test.jpg")!)), viewerShown: .constant(true)))
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
In contrast, this code produces the desired result of the image viewer being above the tab bar:
struct ContentView: View {
var body: some View {
TabView {
Text("Hey")
.tabItem {
Image(systemName: "list.dash")
Text("Menu")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(ImageViewer(image: .constant(Image(uiImage: UIImage(named: "test.jpg")!)), viewerShown: .constant(true)))
}
}
Placing the image viewer on the TabView will fix your issue!
from swiftui-image-viewer.
Thanks for your reply, yeah I know but ImageViewer is not at the same view with tabBar :) I'm gonna place imageViewer at first view and I will trigger it with an observed object, it will work I think. Thanks anyway :)
-- Edit :
It's working well now but now I have a sheet issue :) How can I use it above sheet ? @Jake-Short
from swiftui-image-viewer.
Hello!
Thanks for making this project open source. Works great and very easy to use even for a newb like myself.
I have a question related to positioning. I thought I would ask here instead of creating a new issue as it is related.
Here is my struct:
struct ContentView: View {
var body: some View {
ScrollView {
// More Views
}
.overlay(ImageViewer(image: .constant(Image(uiImage: UIImage(named: "test.jpg")!)), viewerShown: .constant(true)))
.edgesIgnoringSafeArea(.all)
.navigationBarTitle("Navigation Bar Title")
.navigationBarItems(leading:trailing:)
}
}
The problem is that the navigation bar item(s) and back button are in front of the overlay. Instead, I'd like the overlay to be in front of and block them. How could I achieve this?
Thanks!
from swiftui-image-viewer.
@OEssHRERLr770rGGLOH0 Hey! (If you want to, you may skip to the solution below.)
Effect of SwiftUI on functionality
There are a couple of things regarding the way that SwiftUI is built that makes the image viewer act in this way. First, the .overlay modifier only applies to the view that it is being applied to. In the example you provided, it appears that that particular screen is a child of a NavigationView. Therefore, the NavigationView elements (title, buttons, etc.) are all above the overlay, since the overlay is on a child of said NavigationView.
This package is built mainly using, and intended for, SwiftUI. To present a view that would be above all elements no matter their position in the parent/child hierarchy would require a fallback into UIKit, which is currently undesired.
Solution
The way to solve this is to place the .overlay
on the NavigationView. You can have the image/viewerShown state variables stored in the root view (where your NavigationView is) and pass it to the children using binding.
from swiftui-image-viewer.
Effect of SwiftUI on functionality
There are a couple of things regarding the way that SwiftUI is built that makes the image viewer act in this way. First, the .overlay modifier only applies to the view that it is being applied to. In the example you provided, it appears that that particular screen is a child of a NavigationView. Therefore, the NavigationView elements (title, buttons, etc.) are all above the overlay, since the overlay is on a child of said NavigationView.
Make sense. And yes it is a child of a NavigationView.
(If you want to, you may skip to the solution below.)
I had somehow overlooked the relationship between Navigation View and children so I'm grateful for your explanation as it clarifies the behavior of the Navigation Bar. 👍
This package is built mainly using, and intended for, SwiftUI. To present a view that would be above all elements no matter their position in the parent/child hierarchy would require a fallback into UIKit, which is currently undesired.
Completely understandable.
Solution
The way to solve this is to place the
.overlay
on the NavigationView. You can have the image/viewerShown state variables stored in the root view (where your NavigationView is) and pass it to the children using binding.
Sounds like something I should be able to implement. Thanks so much for the help!
from swiftui-image-viewer.
No problem! I'm glad you got it fixed :)
from swiftui-image-viewer.
Related Issues (20)
- Print statements in SPM version. HOT 1
- Support of last version of URLImage HOT 6
- Captions for images HOT 1
- Does it support to swipe to the next or pre image? HOT 7
- ImageViewerRemote wants a valid URL too early HOT 1
- import ImageViewer // <=== File 'ContentView.swift' is part of module 'ImageViewer'; ignoring import HOT 4
- Can we move the close btn to right top? HOT 1
- Ability to disable the automatic zoom out when pinch end. HOT 2
- Resolution difference between simulator and physical device
- Ability to zoom by double tapping?
- How to disable the close button? HOT 1
- Caption text doesnt response change HOT 2
- Can stop rescaling when zooming?
- UIKit Dependency? Not suitable for MacOS HOT 1
- The imageViewer should stay on zoomed scale value and should be closed with zooming when scale is 1
- Support the ability to pass an array of images the user can swipe left and right to view them. HOT 1
- Missing License HOT 1
- Install issues HOT 1
- Portrait images are stretched horizontally HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftui-image-viewer.