changeset 43:2eb05f396fcd v1.2

Fixes NavigationView bugs
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Mon, 26 Jul 2021 17:35:57 +0100
parents d25b02d439d4
children 415d51d6923f
files Simoleon.xcodeproj/project.pbxproj Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon/ContentView.swift Simoleon/Conversion.swift Simoleon/Favourites.swift Simoleon/Helpers/CurrencySelector.swift Simoleon/Settings.swift
diffstat 7 files changed, 41 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/Simoleon.xcodeproj/project.pbxproj	Mon Jul 26 15:35:06 2021 +0100
+++ b/Simoleon.xcodeproj/project.pbxproj	Mon Jul 26 17:35:57 2021 +0100
@@ -699,7 +699,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 13;
+				CURRENT_PROJECT_VERSION = 14;
 				DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\"";
 				DEVELOPMENT_TEAM = MTX83R5H8X;
 				ENABLE_PREVIEWS = YES;
@@ -724,7 +724,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 13;
+				CURRENT_PROJECT_VERSION = 14;
 				DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\"";
 				DEVELOPMENT_TEAM = MTX83R5H8X;
 				ENABLE_PREVIEWS = YES;
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/Simoleon/ContentView.swift	Mon Jul 26 15:35:06 2021 +0100
+++ b/Simoleon/ContentView.swift	Mon Jul 26 17:35:57 2021 +0100
@@ -20,6 +20,7 @@
                     Image(systemName: "arrow.counterclockwise.circle")
                 }
                 .tag(Tab.convert)
+                .accessibilityIdentifier("Convert")
             
             Favourites()
                 .tabItem {
@@ -27,6 +28,7 @@
                     Image(systemName: "star")
                 }
                 .tag(Tab.favourites)
+                .accessibilityIdentifier("Favourites")
             
             Settings()
                 .tabItem {
@@ -34,6 +36,7 @@
                     Image(systemName: "gear")
                 }
                 .tag(Tab.settings)
+                .accessibilityIdentifier("Settings")
         }
     }
     
--- a/Simoleon/Conversion.swift	Mon Jul 26 15:35:06 2021 +0100
+++ b/Simoleon/Conversion.swift	Mon Jul 26 17:35:57 2021 +0100
@@ -9,6 +9,7 @@
 import Purchases
 
 struct Conversion: View {
+    var showNavigationView: Bool?
     @State var currencyPair: String
     @State private var amountToConvert = "1000"
     @State private var price: Double = 1.00
@@ -31,6 +32,7 @@
                                     .padding(.horizontal)
                             )
                     }
+                    .accessibilityIdentifier("CurrencySelector")
                     
                     FavouriteButton(currencyPair: currencyPair)
                 }
@@ -51,7 +53,7 @@
         .onAppear(perform: request)
         .navigationTitle(Text("Convert", comment: "Navigation title"))
         .toolbar {
-            ToolbarItem(placement: .cancellationAction) {
+            ToolbarItem(placement: .navigationBarTrailing) {
                 if amountIsEditing {
                     Button(action: {
                         UIApplication.shared.dismissKeyboard()
@@ -62,7 +64,7 @@
                 }
             }
         }
-        .if(UIDevice.current.userInterfaceIdiom == .phone) { content in
+        .if(UIDevice.current.userInterfaceIdiom == .phone && showNavigationView ?? true) { content in
             NavigationView { content }
         }
     }
--- a/Simoleon/Favourites.swift	Mon Jul 26 15:35:06 2021 +0100
+++ b/Simoleon/Favourites.swift	Mon Jul 26 17:35:57 2021 +0100
@@ -25,7 +25,7 @@
             } else {
                 List {
                     ForEach(favourite) { favourite in
-                        NavigationLink(destination: Conversion(currencyPair: favourite.currencyPair)) {
+                        NavigationLink(destination: Conversion(showNavigationView: false, currencyPair: favourite.currencyPair)) {
                             CurrencyRow(currencyPair: favourite.currencyPair)
                         }
                     }
--- a/Simoleon/Helpers/CurrencySelector.swift	Mon Jul 26 15:35:06 2021 +0100
+++ b/Simoleon/Helpers/CurrencySelector.swift	Mon Jul 26 17:35:57 2021 +0100
@@ -19,15 +19,18 @@
         NavigationView {
             Form {
                 TextField("Search ...", text: $searchCurrency)
+                    .accessibilityIdentifier("SearchBar")
                 
                 Section(header: Text("All currencies", comment: "Section header in currency selector")) {
                     ForEach(currencyPairs(), id: \.self) { currencyPair in
                         Button(action: { select(currencyPair) }) {
                             CurrencyRow(currencyPair: currencyPair)
                         }
+                        .accessibilityIdentifier("CurrencyRowButton")
                     }
                 }
             }
+            .accessibilityIdentifier("AllCurrencies")
             .gesture(DragGesture()
                  .onChanged({ _ in
                     UIApplication.shared.dismissKeyboard()
@@ -68,14 +71,21 @@
      else -> show subscription paywall
      */
     private func select(_ currencyPair: String) {
-        Purchases.shared.purchaserInfo { (purchaserInfo, error) in
-            if purchaserInfo?.entitlements["all"]?.isActive == true {
-                self.currencyPair = currencyPair
-                showingCurrencySelector = false
-            } else {
-                showingSubscriptionPaywall = true
+        #if targetEnvironment(simulator)
+            // We're in simulator
+            self.currencyPair = currencyPair
+            showingCurrencySelector = false
+        #else
+            // We're in physical device
+            Purchases.shared.purchaserInfo { (purchaserInfo, error) in
+                if purchaserInfo?.entitlements["all"]?.isActive == true {
+                    self.currencyPair = currencyPair
+                    showingCurrencySelector = false
+                } else {
+                    showingSubscriptionPaywall = true
+                }
             }
-        }
+        #endif
     }
 }
 
--- a/Simoleon/Settings.swift	Mon Jul 26 15:35:06 2021 +0100
+++ b/Simoleon/Settings.swift	Mon Jul 26 17:35:57 2021 +0100
@@ -81,6 +81,7 @@
             }
         }
         .onAppear {
+            checkEntitlement()
             /*
              if selectedDefaultCurrency is empty -> view is appearing for the first time -> set initial default curency for picker
              else -> view is appearing after user selected another default currency -> save it to core data
@@ -124,15 +125,20 @@
      Check if user subscription is active
      */
     private func checkEntitlement() {
-        Purchases.shared.purchaserInfo { (purchaserInfo, error) in
-            if purchaserInfo?.entitlements["all"]?.isActive == true {
-                entitlementIsActive = true
-                print("Entitlement is active")
-            } else {
-                entitlementIsActive = false
-                print("Entitlement is NOT active")
+        #if targetEnvironment(simulator)
+            // We're in simulator
+            entitlementIsActive = true
+        #else
+            Purchases.shared.purchaserInfo { (purchaserInfo, error) in
+                if purchaserInfo?.entitlements["all"]?.isActive == true {
+                    entitlementIsActive = true
+                    print("Entitlement is active")
+                } else {
+                    entitlementIsActive = false
+                    print("Entitlement is NOT active")
+                }
             }
-        }
+        #endif
     }
 }