how to use NavigationLink(value:label:) inside a List within a NavigationStack or NavigationSplitView - ios16

.navigationTitle("Login")
.padding()
.frame(maxHeight: .infinity,alignment: .top)
.background{
NavigationLink(tag: "VERIFICATION", selection: $otpModel.navigationTag) {
Verification()
.environmentObject(otpModel)
} label: {}
.labelsHidden()
}
.alert(otpModel.errorMsg, isPresented: $otpModel.showAlert) {}
}
}
struct Login_Previews: PreviewProvider {
static var previews: some View {
Login()
}
}
}
error message- 'init(tag:selection:destination:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a List within a NavigationStack or NavigationSplitView
we try to set up code for login in iOS but following message appears and hence code was nearly completed but due to deprecated issue not able to resolve
error message- 'init(tag:selection:destination:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a List within a NavigationStack or NavigationSplitView

Related

WatchOS and iOS new .accessoryInline Widget does not display everything

I'm trying to made an WatchOS extension with the new type .accessoryInlineBut I don"t understand why I cannot have more than one stack in the main horizontal stack.
See the invisible stack in the following commented code and in the WatchOS simulator
struct WidgetInlineView : View {
var entry: BurnoutTimelineEntry
var body: some View {
HStack(spacing: 5) {
HStack {
Image("widgetWork")
Text(entry.exchange.todayWork.durationString)
}
HStack {
Image("widgetPause")
Text(entry.exchange.todayPause.durationString)
}
}
}
}
struct WidgetInline: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(kind: "MyKind", provider: BurnoutTimelineProvider()) { entry in
WidgetInlineView(entry: entry)
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
.supportedFamilies([.accessoryInline])
}
}
struct WidgetInline_Previews: PreviewProvider {
static var previews: some View {
WidgetInlineView(entry: BurnoutTimelineEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .accessoryInline))
}
}
The inline widgets only display the first text item and the first image. Everything else is ignored and they ignore any styling, too. And to top it off, it's very picky about the image size (I have not found the exact limits yet): if your image is too large it won't get rendered, even if you marked it as resizable.
I come to the same conclusion as answered by #DarkDust
Regarding text, my work around is to use text concatenation. something like this...
Text("Hello") + Text("\(name) ") + Text(Image(systemName: "exclamationmark.circle.fill"))

How to change filled icon to not filled on TabView tabItem in iOS 15 Xcode 13?

How can i change filled icon to not filled on TabView tabItem in iOS 15 Xcode 13?
It seems now that the icons are filled by default...
My code :
import SwiftUI
struct Test_Home_V: View {
var body: some View {
TabView {
HomeList_V()
.tabItem {
Label("_HomeTitle", systemImage: "house")
}
...
Note : From iOS 15 you should not explicitly request the filled variant of SF Symbols icons, because the system will automatically use them as appropriate.
So how can I get my icons (SF Symbols) in outline like before?
Thanks
To solve this, we can use environment(\.symbolVariants, .none).
https://developer.apple.com/documentation/swiftui/symbolvariants/none
Using this variant with the symbolVariant(:) modifier doesn’t have
any effect. Instead, to show a symbol that ignores the current
variant, directly set the symbolVariants environment value to none
using the environment(:_:) modifer:
import SwiftUI
struct ContentView: View {
var body: some View {
TabView {
Text("content")
.tabItem {
Label("tab", systemImage: "creditcard")
}
Text("content")
.tabItem {
Label("tab", systemImage: "creditcard")
.environment(\.symbolVariants, .none) // here
}
}
}
}
The result:

Xcode 12: environment overrides setting in panel is not reflected on Simulator

I follow a YouTube video on new stuff of iOS 14. Now we could set environment overrides via the panel. But I found the changes like Text Dynamic type is not reflected on iOS simulator. I search around, it is quite new, no related information I found. Is there anyone met the same issue here, how to fix it?
There is a warning "2020-07-18 11:46:25.479202+0800 SwiftUITest[32945:888273] libMobileGestalt MobileGestaltCache.c:38: No persisted cache on this platform." in the console. Not sure if it is related.
MacOS: 10.15.6 Beta (19G71a)
Xcode: 12.0 beta 2 (12A6163b)
import SwiftUI
struct ContentView: View {
#State private var text = "Hello, world!"
var body: some View {
TextEditor(text: $text)
.padding()
.foregroundColor(.blue)
.font(.custom("Georgia", size: 24, relativeTo: .largeTitle))
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

SwiftUI NavigationLink Text click not working [duplicate]

I was working on an application with login and after login there are categories listed. And under each category there are some items listed horizontally. The thing is after login, main page appears and everything is listed great. When you click on an item it goes to detailed screen but when you try to go back it just crashes. I found this flow Why does my SwiftUI app crash when navigating backwards after placing a `NavigationLink` inside of a `navigationBarItems` in a `NavigationView`? but i could not solve my problem. Since my project become complicated, I just wanted to practice navigation in swiftui and I created a new project. By the way I downloaded the latest xcode version 11.3. I wrote a simple code as follows:
NavigationView{
NavigationLink(destination: Test()) {
Text("Show Detail View")
}
.navigationBarTitle("title1")
And Test() view is as follows:
import SwiftUI
struct Test: View {
var body: some View {
Text("Hello, World!")
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
As you can see it is really simple. I also tried similar examples on the internet but it does not work the way it suppose to work. When I run the project, I click the navigation link and it navigates to Test() view. Then I click back button and it navigates to the main page. However, when I click the navigation link second time, nothing happens. Navigation link works only once and after that nothing happens. It does not navigate, it des not throw any error. I am new to swiftui and everything is great but the navigation. I tried many examples and suggested solutions on the internet, but nothing seems to fix my issues.
[UPDATE] Nov 5, 2020 - pawello2222 says that this issue has been fixed in Xcode 12.1.
[UPDATE] Jun 14, 2020 - Quang Hà says that this issue has come back in Xcode 11.5.
[UPDATE] Feb 12, 2020 - I checked for this issue in Xcode 11.4 beta and found that this issue has been resolved.
I was getting the same issue in my project too, when I was testing it in Xcode's simulator. However, when I launched the app on a real device (iPhone X with iOS 13.3), NavigationLink was working totally fine. So, it really does seem like Xcode's bug.
Simulator 11.4: This issue has been fixed
You need to reset the default isActive value in the second view.
It works on devices and emulators.
struct NavigationViewDemo: View {
#State var isActive = false
var body: some View {
NavigationView {
VStack {
Text("View1")
NavigationLink(
destination: NavigationViewDemo_View2(isActive: $isActive),
isActive: $isActive,
label: { Button(action: { self.isActive = true }, label: { Text("click") }) })
}
}
}
}
struct NavigationViewDemo_View2: View {
#Binding var isActive: Bool
var body: some View {
Text("View2")
.navigationBarItems(leading: Button(action: { self.isActive = false }, label: { Text("Back") }))
}
}
Presumably this will be resolved when Apple fixes the related bug that prevents 13.3 from being selectable as a deployment target.
I'm experiencing the same issue as everyone else. This issue is present in simulator and preview running 13.2, but is fixed when deploying to my own device running 13.3.
As #Александр Грабовский said its seems like a Xcode 11.3 bug, I am encountering the same problem, you must downgrade or use some workaround like custom back button as below
struct ContentView: View {
#State private var pushed: Bool = false
var body: some View {
NavigationView {
VStack {
Button("Show Detail View") {
self.pushed.toggle()
}
NavigationLink(destination: Test(pushed: $pushed), isActive: $pushed) { EmptyView() }
}.navigationBarTitle("title1")
}
}
}
struct Test: View {
#Binding var pushed: Bool
var body: some View {
Text("Hello, World!")
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: BackButton(label: "Back") {
self.pushed = false
})
}
}
struct BackButton: View {
let label: String
let closure: () -> ()
var body: some View {
Button(action: { self.closure() }) {
HStack {
Image(systemName: "chevron.left")
Text(label)
}
}
}
}
For anyone who's having the same symptom with other versions of iOS than the buggy beta identified by other answers, there's another reason you might be seeing this behaviour.
If your NavigationLink is nested inside another NavigationLink, the inner NavigationLink will only work once, unless you add isDetailLink(false) to the outer link.

NavigationLink Works Only for Once

I was working on an application with login and after login there are categories listed. And under each category there are some items listed horizontally. The thing is after login, main page appears and everything is listed great. When you click on an item it goes to detailed screen but when you try to go back it just crashes. I found this flow Why does my SwiftUI app crash when navigating backwards after placing a `NavigationLink` inside of a `navigationBarItems` in a `NavigationView`? but i could not solve my problem. Since my project become complicated, I just wanted to practice navigation in swiftui and I created a new project. By the way I downloaded the latest xcode version 11.3. I wrote a simple code as follows:
NavigationView{
NavigationLink(destination: Test()) {
Text("Show Detail View")
}
.navigationBarTitle("title1")
And Test() view is as follows:
import SwiftUI
struct Test: View {
var body: some View {
Text("Hello, World!")
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
As you can see it is really simple. I also tried similar examples on the internet but it does not work the way it suppose to work. When I run the project, I click the navigation link and it navigates to Test() view. Then I click back button and it navigates to the main page. However, when I click the navigation link second time, nothing happens. Navigation link works only once and after that nothing happens. It does not navigate, it des not throw any error. I am new to swiftui and everything is great but the navigation. I tried many examples and suggested solutions on the internet, but nothing seems to fix my issues.
[UPDATE] Nov 5, 2020 - pawello2222 says that this issue has been fixed in Xcode 12.1.
[UPDATE] Jun 14, 2020 - Quang Hà says that this issue has come back in Xcode 11.5.
[UPDATE] Feb 12, 2020 - I checked for this issue in Xcode 11.4 beta and found that this issue has been resolved.
I was getting the same issue in my project too, when I was testing it in Xcode's simulator. However, when I launched the app on a real device (iPhone X with iOS 13.3), NavigationLink was working totally fine. So, it really does seem like Xcode's bug.
Simulator 11.4: This issue has been fixed
You need to reset the default isActive value in the second view.
It works on devices and emulators.
struct NavigationViewDemo: View {
#State var isActive = false
var body: some View {
NavigationView {
VStack {
Text("View1")
NavigationLink(
destination: NavigationViewDemo_View2(isActive: $isActive),
isActive: $isActive,
label: { Button(action: { self.isActive = true }, label: { Text("click") }) })
}
}
}
}
struct NavigationViewDemo_View2: View {
#Binding var isActive: Bool
var body: some View {
Text("View2")
.navigationBarItems(leading: Button(action: { self.isActive = false }, label: { Text("Back") }))
}
}
Presumably this will be resolved when Apple fixes the related bug that prevents 13.3 from being selectable as a deployment target.
I'm experiencing the same issue as everyone else. This issue is present in simulator and preview running 13.2, but is fixed when deploying to my own device running 13.3.
As #Александр Грабовский said its seems like a Xcode 11.3 bug, I am encountering the same problem, you must downgrade or use some workaround like custom back button as below
struct ContentView: View {
#State private var pushed: Bool = false
var body: some View {
NavigationView {
VStack {
Button("Show Detail View") {
self.pushed.toggle()
}
NavigationLink(destination: Test(pushed: $pushed), isActive: $pushed) { EmptyView() }
}.navigationBarTitle("title1")
}
}
}
struct Test: View {
#Binding var pushed: Bool
var body: some View {
Text("Hello, World!")
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: BackButton(label: "Back") {
self.pushed = false
})
}
}
struct BackButton: View {
let label: String
let closure: () -> ()
var body: some View {
Button(action: { self.closure() }) {
HStack {
Image(systemName: "chevron.left")
Text(label)
}
}
}
}
For anyone who's having the same symptom with other versions of iOS than the buggy beta identified by other answers, there's another reason you might be seeing this behaviour.
If your NavigationLink is nested inside another NavigationLink, the inner NavigationLink will only work once, unless you add isDetailLink(false) to the outer link.

Resources