From c181347dd901267af69aae915dc069c40dab2098 Mon Sep 17 00:00:00 2001 From: Astemir Eleev Date: Mon, 15 Aug 2022 21:08:22 +0300 Subject: [PATCH 1/3] Fix compiler warnings related to SwiftUI and applied structural refactoring --- .../Models/Board/GameBoardSizeState.swift | 10 +- T2iles/Sources/Models/Board/GameLogic.swift | 45 ++++--- .../Styles/FilledBackgroundStyle.swift | 2 +- .../BottomSlidableModalModifier.swift | 20 +-- .../View Modifiers/MainViewModifier.swift | 14 +- .../RoundedClippedBackground.swift | 2 +- .../View Modifiers/SlideViewModifier.swift | 7 +- .../Views/Game/GameStateBottomView.swift | 120 ++++++++++++------ T2iles/Sources/Views/Game/TileBoardView.swift | 23 ++-- T2iles/Sources/Views/Main/CompositeView.swift | 112 +++++++++------- T2iles/Sources/Views/Main/HeaderView.swift | 13 +- .../Views/Settings/AudioSettingView.swift | 25 ++-- .../Sources/Views/Settings/SettingsView.swift | 12 +- .../Views/Settings/TileBoardSettingView.swift | 8 +- .../Views/Side/CompositeSideView.swift | 3 +- T2iles/Sources/Views/Side/SideMenuView.swift | 12 +- 16 files changed, 257 insertions(+), 171 deletions(-) diff --git a/T2iles/Sources/Models/Board/GameBoardSizeState.swift b/T2iles/Sources/Models/Board/GameBoardSizeState.swift index 9ada67f..079d1c9 100644 --- a/T2iles/Sources/Models/Board/GameBoardSizeState.swift +++ b/T2iles/Sources/Models/Board/GameBoardSizeState.swift @@ -15,7 +15,7 @@ struct GameBoardSizeState { private(set) var boardSize: BoardSize = .fourByFour { didSet { defaults.set(boardSize.rawValue, forKey: Notification.Name.gameBoardSize.rawValue) - self.publishState() + publishState() } } @@ -88,8 +88,10 @@ struct GameBoardSizeState { // MARK: - Private Methods private func publishState() { - NotificationCenter.default.post(name: .gameBoardSize, - object: nil, - userInfo: [Notification.Name.gameBoardSizeUserInfoKey : boardSize]) + NotificationCenter.default.post( + name: .gameBoardSize, + object: nil, + userInfo: [Notification.Name.gameBoardSizeUserInfoKey : boardSize] + ) } } diff --git a/T2iles/Sources/Models/Board/GameLogic.swift b/T2iles/Sources/Models/Board/GameLogic.swift index 9f572ff..057298b 100644 --- a/T2iles/Sources/Models/Board/GameLogic.swift +++ b/T2iles/Sources/Models/Board/GameLogic.swift @@ -45,7 +45,7 @@ final class GameLogic: ObservableObject { // MARK: - Initializers init(size: Int) { - self.boardSize = size + boardSize = size reset(boardSize: size) NotificationCenter @@ -54,10 +54,10 @@ final class GameLogic: ObservableObject { .map { $0.userInfo?[Notification.Name.gameBoardSizeUserInfoKey] as? BoardSize } - .sink { + .sink { [unowned self] in guard let gameBoardSize = $0 else { return } let rawValue = gameBoardSize.rawValue - self.reset(boardSize: rawValue) + reset(boardSize: rawValue) }.store(in: &cancellables) } @@ -93,11 +93,13 @@ final class GameLogic: ObservableObject { var rowSnapshot = [IdentifiedTile?]() var compactRow = [IdentifiedTile]() - computeIntermediateSnapshot(&rowSnapshot, - &compactRow, - axis: axis, - currentRow: row) - + computeIntermediateSnapshot( + &rowSnapshot, + &compactRow, + axis: axis, + currentRow: row + ) + if merge(blocks: &compactRow, reverse: direction == .down || direction == .right) { hasMergedBlocks = true } @@ -116,17 +118,21 @@ final class GameLogic: ObservableObject { tileMatrix.add($1, to: axis ? ($0, row) : (row, $0)) } } - return finalizeMove(previousMatrixSnapshot, - hasMoved: moved, - hasMergedBlocks: hasMergedBlocks) + return finalizeMove( + previousMatrixSnapshot, + hasMoved: moved, + hasMergedBlocks: hasMergedBlocks + ) } // MARK: - Private Methods - private func computeIntermediateSnapshot(_ rowSnapshot: inout [IdentifiedTile?], - _ compactRow: inout [IdentifiedTile], - axis: Bool, - currentRow row: Int) { + private func computeIntermediateSnapshot( + _ rowSnapshot: inout [IdentifiedTile?], + _ compactRow: inout [IdentifiedTile], + axis: Bool, + currentRow row: Int + ) { for col in 0.. Void = { } + let sideMenuDragHeight: CGFloat = 100 func body(content: Content) -> some View { content - .offset(y: self.presentEndGameModal ? (proxy.size.height / 2.0) : (proxy.size.height + proxy.size.height / 2)) - .offset(y: self.sideMenuViewState.height) - .animation(.modalSpring) + .offset(y: presentEndGameModal ? (proxy.size.height / 2.0) : (proxy.size.height + proxy.size.height / 2)) + .offset(y: sideMenuViewState.height) + .animation(.modalSpring, value: presentEndGameModal) .gesture( DragGesture().onChanged { value in if value.translation.height > 0 { - self.sideMenuViewState.height = value.translation.height + sideMenuViewState.height = value.translation.height } } .onEnded { value in - if self.sideMenuViewState.height > 100 { - + if sideMenuViewState.height > sideMenuDragHeight { withAnimation(.modalSpring) { - self.presentEndGameModal = false - self.hasGameEnded = false - self.onGameEndCompletion() + presentEndGameModal = false + hasGameEnded = false + onGameEndCompletion() } } - self.sideMenuViewState = .zero + sideMenuViewState = .zero } ) } diff --git a/T2iles/Sources/View Modifiers/MainViewModifier.swift b/T2iles/Sources/View Modifiers/MainViewModifier.swift index 68253a9..1f691f0 100644 --- a/T2iles/Sources/View Modifiers/MainViewModifier.swift +++ b/T2iles/Sources/View Modifiers/MainViewModifier.swift @@ -17,12 +17,12 @@ struct MainViewModifier: ViewModifier { func body(content: Content) -> some View { content - .offset(y: self.presentEndGameModal ? self.horizontalSizeClass == .regular ? (proxy.size.width < proxy.size.height ? -proxy.size.height / 4 : -proxy.size.height / 3) : -proxy.size.height / 3 : 0) - .rotation3DEffect(Angle(degrees: self.presentEndGameModal ? proxy.size.width < proxy.size.height ? Double(self.viewState.height / 10) - 10 : Double(self.viewState.height / 10) - 20 : 0), axis: (x: 10.0, y: 0, z: 0)) - .scaleEffect(self.presentEndGameModal ? 0.9 : 1) - .rotation3DEffect(Angle(degrees: self.presentSideMenu ? Double(self.viewState.width / 10) - (self.horizontalSizeClass == .regular ? 10 : 20) : 0), axis: (x: 0, y: 10, z: 0)) - .offset(x: self.presentSideMenu ? (self.horizontalSizeClass == .regular ? proxy.size.width / 3 : proxy.size.width / 1.5) : 0) - .offset(x: -self.viewState.width) - .scaleEffect(self.presentSideMenu ? 0.9 : 1) + .offset(y: presentEndGameModal ? horizontalSizeClass == .regular ? (proxy.size.width < proxy.size.height ? -proxy.size.height / 4 : -proxy.size.height / 3) : -proxy.size.height / 3 : 0) + .rotation3DEffect(Angle(degrees: presentEndGameModal ? proxy.size.width < proxy.size.height ? Double(viewState.height / 10) - 10 : Double(viewState.height / 10) - 20 : 0), axis: (x: 10.0, y: 0, z: 0)) + .scaleEffect(presentEndGameModal ? 0.9 : 1) + .rotation3DEffect(Angle(degrees: presentSideMenu ? Double(viewState.width / 10) - (horizontalSizeClass == .regular ? 10 : 20) : 0), axis: (x: 0, y: 10, z: 0)) + .offset(x: presentSideMenu ? (horizontalSizeClass == .regular ? proxy.size.width / 3 : proxy.size.width / 1.5) : 0) + .offset(x: -viewState.width) + .scaleEffect(presentSideMenu ? 0.9 : 1) } } diff --git a/T2iles/Sources/View Modifiers/RoundedClippedBackground.swift b/T2iles/Sources/View Modifiers/RoundedClippedBackground.swift index 1b7fcab..94d9977 100644 --- a/T2iles/Sources/View Modifiers/RoundedClippedBackground.swift +++ b/T2iles/Sources/View Modifiers/RoundedClippedBackground.swift @@ -14,7 +14,7 @@ struct RoundedClippedBackground: ViewModifier { func body(content: Content) -> some View { content - .background(Rectangle().fill(self.backgroundColor)) + .background(Rectangle().fill(backgroundColor)) .clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous)) .shadow(color: Color.primary.opacity(0.3), radius: 20) } diff --git a/T2iles/Sources/View Modifiers/SlideViewModifier.swift b/T2iles/Sources/View Modifiers/SlideViewModifier.swift index 47a971a..e136061 100644 --- a/T2iles/Sources/View Modifiers/SlideViewModifier.swift +++ b/T2iles/Sources/View Modifiers/SlideViewModifier.swift @@ -9,15 +9,14 @@ import SwiftUI struct SlideViewModifier: ViewModifier { - var gesture: T @Binding var presentEndGameModal: Bool @Binding var presentSideMenu: Bool func body(content: Content) -> some View { content - .gesture(self.gesture, including: .all) - .scaleEffect((self.presentEndGameModal || self.presentSideMenu) ? 0.9 : 1.0) - .allowsHitTesting(!(self.presentEndGameModal || self.presentSideMenu)) + .gesture(gesture, including: .all) + .scaleEffect((presentEndGameModal || presentSideMenu) ? 0.9 : 1.0) + .allowsHitTesting(!(presentEndGameModal || presentSideMenu)) } } diff --git a/T2iles/Sources/Views/Game/GameStateBottomView.swift b/T2iles/Sources/Views/Game/GameStateBottomView.swift index dcaabfb..b399bf3 100644 --- a/T2iles/Sources/Views/Game/GameStateBottomView.swift +++ b/T2iles/Sources/Views/Game/GameStateBottomView.swift @@ -10,6 +10,8 @@ import SwiftUI struct GameStateBottomView: View { + // MARK: - Properties + @Binding var hasGameEnded: Bool @Binding var presentEndGameModal: Bool @Binding var sideMenuViewState: CGSize @@ -19,54 +21,92 @@ struct GameStateBottomView: View { private let plist = PlistConfiguration(name: "Strings") private let gameBoardState: [String : [String : String]] - init(hasGameEnded: Binding, - presentEndGameModal: Binding, - sideMenuViewState: Binding, - score: Binding, - resetGame: @escaping () -> Void) { - self._hasGameEnded = hasGameEnded - self._presentEndGameModal = presentEndGameModal - self._sideMenuViewState = sideMenuViewState - self._score = score + // MARK: - Initializers + + init( + hasGameEnded: Binding, + presentEndGameModal: Binding, + sideMenuViewState: Binding, + score: Binding, + resetGame: @escaping () -> Void + ) { + _hasGameEnded = hasGameEnded + _presentEndGameModal = presentEndGameModal + _sideMenuViewState = sideMenuViewState + _score = score self.resetGame = resetGame gameBoardState = plist?.getItem(named: PlistConfigurationKeyPath.gameState.rawValue) ?? ["" : [:]] } + // MARK: - Views + + private var modalGameEnd: some View { + ModalView( + title: gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.gameOverTitle.rawValue] ?? "", + subtitle: (gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.gameOverSubtitle.rawValue] ?? "") + "\(score)", + completionHandler: { + withAnimation(.modalSpring) { + resetGame() + presentEndGameModal = false + } + hasGameEnded = false + } + ) + } + + private var modalExistingGame: some View { + ModalView( + title: gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.resetGameTitle.rawValue] ?? "", + subtitle: gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.resetGameSubtitle.rawValue] ?? "", + completionHandler: { + withAnimation(.modalSpring) { + resetGame() + presentEndGameModal = false + } + } + ) { + withAnimation(.modalSpring) { + presentEndGameModal = false + } + } + } + + // MARK: - Conformance to View protocol + var body: some View { GeometryReader { proxy in - if self.hasGameEnded { - ModalView(title: gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.gameOverTitle.rawValue] ?? "", - subtitle: (gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.gameOverSubtitle.rawValue] ?? "") + "\(score)", completionHandler: { - withAnimation(.modalSpring) { - resetGame() - presentEndGameModal = false - } - hasGameEnded = false - }) - .modifier(BottomSlidableModalModifier(proxy: proxy, - presentEndGameModal: $presentEndGameModal, - sideMenuViewState: $sideMenuViewState, - hasGameEnded: $hasGameEnded, - onGameEndCompletion: { - resetGame() // Reset the game on interactive dismiss gesture - })) - } else { - ModalView(title: gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.resetGameTitle.rawValue] ?? "", subtitle: gameBoardState[PlistConfigurationKeyPath.gameState.rawValue]?[PlistConfigurationKeyPath.resetGameSubtitle.rawValue] ?? "", completionHandler: { - withAnimation(.modalSpring) { - resetGame() - presentEndGameModal = false - } - }) { - withAnimation(.modalSpring) { - presentEndGameModal = false - } - } - .modifier(BottomSlidableModalModifier(proxy: proxy, - presentEndGameModal: $presentEndGameModal, - sideMenuViewState: $sideMenuViewState, - hasGameEnded: .constant(false))) + switch hasGameEnded { + case true: + modalGameEnd + .modifier(bottomGameOverSheet(proxy)) + case false: + modalExistingGame + .modifier(bottomExistingGameSheet(proxy)) } } } + + // MARK: - Private View Modifiers + + private func bottomGameOverSheet(_ proxy: GeometryProxy) -> some ViewModifier { + BottomSlidableModalModifier( + proxy: proxy, + presentEndGameModal: $presentEndGameModal, + sideMenuViewState: $sideMenuViewState, + hasGameEnded: $hasGameEnded, + onGameEndCompletion: { + resetGame() // Reset the game on interactive dismiss gesture + } + ) + } + + private func bottomExistingGameSheet(_ proxy: GeometryProxy) -> some ViewModifier { + BottomSlidableModalModifier( + proxy: proxy, + presentEndGameModal: $presentEndGameModal, + sideMenuViewState: $sideMenuViewState, + hasGameEnded: .constant(false) + ) + } } diff --git a/T2iles/Sources/Views/Game/TileBoardView.swift b/T2iles/Sources/Views/Game/TileBoardView.swift index 9e967f1..c54f0a8 100644 --- a/T2iles/Sources/Views/Game/TileBoardView.swift +++ b/T2iles/Sources/Views/Game/TileBoardView.swift @@ -39,16 +39,14 @@ struct TileBoardView: View { createBlock(nil, at: (x, y), proxy: proxy) } } - ForEach(matrix.flatten(), id: \.tile.id) { item in createBlock(item.tile, at: item.index, proxy: proxy) } - .animation( - .interpolatingSpring(stiffness: 800, damping: 200) - ) } - .frame(width: calculateFrameSize(proxy), - height: calculateFrameSize(proxy), alignment: .center) + .frame( + width: calculateFrameSize(proxy), + height: calculateFrameSize(proxy), alignment: .center + ) .background( Rectangle() .fill(Color(red:0.76, green:0.76, blue:0.78, opacity: 1)) @@ -62,10 +60,11 @@ struct TileBoardView: View { // MARK: - Methods - func createBlock(_ block: IdentifiedTile?, - at index: IndexedTile.Index, - proxy: GeometryProxy - ) -> some View { + func createBlock( + _ block: IdentifiedTile?, + at index: IndexedTile.Index, + proxy: GeometryProxy + ) -> some View { let blockView: TileView if let block = block { blockView = TileView(number: block.value) @@ -90,6 +89,10 @@ struct TileBoardView: View { position: CGPoint(x: position.x, y: position.y), in: CGRect(x: 0, y: 0, width: frameSize, height: frameSize) )) + .animation( + .interpolatingSpring(stiffness: 800, damping: 200), + value: position + ) } // MARK: - Private Methods diff --git a/T2iles/Sources/Views/Main/CompositeView.swift b/T2iles/Sources/Views/Main/CompositeView.swift index cff5b75..16be50d 100644 --- a/T2iles/Sources/Views/Main/CompositeView.swift +++ b/T2iles/Sources/Views/Main/CompositeView.swift @@ -11,6 +11,8 @@ import Combine struct CompositeView: View { + // MARK: - Proeprties + @Environment(\.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass? @State private var ignoreGesture = false @@ -31,46 +33,51 @@ struct CompositeView: View { @AppStorage(AppStorageKeys.audio.rawValue) var isAudioEnabled: Bool = true + // MARK: - Initializers + init(board: GameLogic) { self.logic = board } + // MARK: - Drag Gesture + private var gesture: some Gesture { let threshold: CGFloat = 25 let drag = DragGesture() .onChanged { v in - guard !self.ignoreGesture else { return } + guard !ignoreGesture else { return } guard abs(v.translation.width) > threshold || abs(v.translation.height) > threshold else { return } - withTransaction(Transaction()) { - self.ignoreGesture = true + ignoreGesture = true if v.translation.width > threshold { // Move right - self.logic.move(.right) + logic.move(.right) } else if v.translation.width < -threshold { // Move left - self.logic.move(.left) + logic.move(.left) } else if v.translation.height > threshold { // Move down - self.logic.move(.down) + logic.move(.down) } else if v.translation.height < -threshold { // Move up - self.logic.move(.up) + logic.move(.up) } } } .onEnded { _ in - self.ignoreGesture = false + ignoreGesture = false } return drag } + // MARK: - Comformance to View protocol + var body: some View { GeometryReader { proxy in ZStack(alignment: .top) { @@ -78,12 +85,14 @@ struct CompositeView: View { Group { self.headerView(proxy) - FactoryContentView(selectedView: $selectedView, - gesture: gesture, - gameLogic: logic, - presentEndGameModal: $presentEndGameModal, - presentSideMenu: $presentSideMenu) - .onReceive(logic.$score) { (publishedScore) in + FactoryContentView( + selectedView: $selectedView, + gesture: gesture, + gameLogic: logic, + presentEndGameModal: $presentEndGameModal, + presentSideMenu: $presentSideMenu + ) + .onReceive(logic.$score) { (publishedScore) in score = publishedScore } .onReceive(logic.$mergeMultiplier) { (publishedScoreMultiplier) in @@ -98,12 +107,16 @@ struct CompositeView: View { } .modifier(RoundedClippedBackground(backgroundColor: colorSchemeBackgroundTheme.backgroundColor(for: colorScheme), proxy: proxy)) - .modifier(MainViewModifier(proxy: proxy, - presentEndGameModal: $presentEndGameModal, - presentSideMenu: $presentSideMenu, - viewState: $viewState)) - .onTapGesture { - guard !hasGameEnded else { return } // Disable on tap dismissal of the end game modal view + .modifier( + MainViewModifier( + proxy: proxy, + presentEndGameModal: $presentEndGameModal, + presentSideMenu: $presentSideMenu, + viewState: $viewState + ) + ) + .onTapGesture { + guard !hasGameEnded else { return } // Disable on tap dismissal of the end game modal view withAnimation(.modalSpring) { presentEndGameModal = false @@ -119,15 +132,18 @@ struct CompositeView: View { } } - GameStateBottomView(hasGameEnded: $hasGameEnded, - presentEndGameModal: $presentEndGameModal, - sideMenuViewState: $sideMenuViewState, - score: $score, - resetGame: resetGame) - - CompositeSideView(selectedView: $selectedView, - sideMenuViewState: $sideMenuViewState, - presentSideMenu: $presentSideMenu) + GameStateBottomView( + hasGameEnded: $hasGameEnded, + presentEndGameModal: $presentEndGameModal, + sideMenuViewState: $sideMenuViewState, + score: $score, + resetGame: resetGame + ) + CompositeSideView( + selectedView: $selectedView, + sideMenuViewState: $sideMenuViewState, + presentSideMenu: $presentSideMenu + ) } } .edgesIgnoringSafeArea(.all) @@ -136,17 +152,19 @@ struct CompositeView: View { // MARK: - Methods private func headerView(_ proxy: GeometryProxy) -> some View { - HeaderView(proxy: proxy, - showSideMenu: $presentSideMenu, - title: selectedView.title, - score: $score, - scoreMultiplier: $scoreMultiplier, - newGameAction: { - presentEndGameModal = true - }, - showResetButton: { - selectedView == .game - }) + HeaderView( + proxy: proxy, + showSideMenu: $presentSideMenu, + title: selectedView.title, + score: $score, + scoreMultiplier: $scoreMultiplier, + newGameAction: { + presentEndGameModal = true + }, + showResetButton: { + selectedView == .game + } + ) } private func resetGame() { @@ -154,14 +172,20 @@ struct CompositeView: View { } } +// MARK: - Previews + struct CompositeView_Previews : PreviewProvider { static var previews: some View { Group { - CompositeView(board: GameLogic(size: BoardSize.fourByFour.rawValue)) - .colorScheme(.dark) + CompositeView( + board: GameLogic(size: BoardSize.fourByFour.rawValue) + ) + .colorScheme(.dark) - CompositeView(board: GameLogic(size: BoardSize.fourByFour.rawValue)) - .colorScheme(.light) + CompositeView( + board: GameLogic(size: BoardSize.fourByFour.rawValue) + ) + .colorScheme(.light) } } } diff --git a/T2iles/Sources/Views/Main/HeaderView.swift b/T2iles/Sources/Views/Main/HeaderView.swift index 162f4d7..05d1f19 100644 --- a/T2iles/Sources/Views/Main/HeaderView.swift +++ b/T2iles/Sources/Views/Main/HeaderView.swift @@ -27,7 +27,8 @@ struct HeaderView: View { // MARK: - Compited View Propeties private var scoreView: some View { - HStack { + let shouldShowReset = showResetButton() + return HStack { Text("Score") .font(Font.system(.title, design: .monospaced).weight(.black)) .foregroundColor(Color(red:0.49, green:0.49, blue:0.49, opacity: 0.7)) @@ -36,7 +37,7 @@ struct HeaderView: View { .font(Font.system(.title, design: .monospaced).weight(.black)) .foregroundColor(Color(red:0.59, green:0.59, blue:0.59, opacity: 1.00)) .transition(AnyTransition.move(edge: .bottom).combined(with: .opacity)) - .animation(.modalSpring) + .animation(.modalSpring, value: shouldShowReset) .id("Score \(self.score)") Text("x\(scoreMultiplier)") @@ -44,9 +45,9 @@ struct HeaderView: View { .foregroundColor(Color.primary.opacity(0.7)) .alignmentGuide(VerticalAlignment.center, computeValue: { $0[.bottom] }) } - .opacity(showResetButton() ? 1.0 : 0.0) + .opacity(shouldShowReset ? 1.0 : 0.0) .transition(AnyTransition.move(edge: .trailing).combined(with: .opacity)) - .animation(Animation.modalSpring) + .animation(.modalSpring, value: shouldShowReset) .id("Score hview: \(showResetButton())") } @@ -83,7 +84,7 @@ struct HeaderView: View { } .foregroundColor(.gray) .padding() - .opacity(self.showResetButton() ? 1.0 : 0.0) + .opacity(showResetButton() ? 1.0 : 0.0) } private var titleView: some View { @@ -91,7 +92,7 @@ struct HeaderView: View { .font(Font.system(size: 46).weight(.black)) .foregroundColor(Color(red:0.29, green:0.29, blue:0.29, opacity: 1.00)) .transition(AnyTransition.move(edge: .trailing).combined(with: .opacity)) - .animation(Animation.modalSpring) + .animation(.modalSpring, value: showSideMenu) .id(title) } diff --git a/T2iles/Sources/Views/Settings/AudioSettingView.swift b/T2iles/Sources/Views/Settings/AudioSettingView.swift index 3cc0be2..a1020d3 100644 --- a/T2iles/Sources/Views/Settings/AudioSettingView.swift +++ b/T2iles/Sources/Views/Settings/AudioSettingView.swift @@ -50,21 +50,24 @@ struct AudioSettingView: View { .aspectRatio(contentMode: .fit) .frame(height: previewSize.height / 3) .id(systemImageName) - .transition(.asymmetric(insertion: - AnyTransition - .opacity - .combined(with: .scale(scale: 1.0)) - .animation(Animation.modalSpring), - removal: - AnyTransition - .opacity - .combined(with: .scale(scale: 0.0)) - .animation(Animation.modalSpring))) + .transition( + .asymmetric( + insertion: AnyTransition + .opacity + .combined(with: .scale(scale: 1.0)) + .animation(.modalSpring), + removal: + AnyTransition + .opacity + .combined(with: .scale(scale: 0.0)) + .animation(.modalSpring) + ) + ) } .toggleStyle(CheckboxToggleStyle()) .foregroundColor(Color.primary.opacity(0.5)) .shadow(color: invertedBackgroundColor.opacity(0.5), radius: 10) - .animation(.modalSpring) + .animation(.modalSpring, value: isAudioEnabled) .padding([.leading, .leading, .top, .bottom]) } } diff --git a/T2iles/Sources/Views/Settings/SettingsView.swift b/T2iles/Sources/Views/Settings/SettingsView.swift index 4ee488f..64b7420 100644 --- a/T2iles/Sources/Views/Settings/SettingsView.swift +++ b/T2iles/Sources/Views/Settings/SettingsView.swift @@ -47,8 +47,10 @@ struct SettingsView: View { .fontWeight(.bold) } ) { - TileBoardSettingView(invertedBackgroundColor: self.invertedBackgroundColor, - previewSize: self.previewSize) + TileBoardSettingView( + invertedBackgroundColor: invertedBackgroundColor, + previewSize: previewSize + ) } Section(header: VStack(alignment: .leading) { @@ -62,8 +64,10 @@ struct SettingsView: View { .fontWeight(.bold) } ) { - AudioSettingView(invertedBackground: self.invertedBackgroundColor, - previewSize: self.previewSize) + AudioSettingView( + invertedBackground: invertedBackgroundColor, + previewSize: previewSize + ) } } .listStyle(InsetGroupedListStyle()) diff --git a/T2iles/Sources/Views/Settings/TileBoardSettingView.swift b/T2iles/Sources/Views/Settings/TileBoardSettingView.swift index 60c64fe..3d88af1 100644 --- a/T2iles/Sources/Views/Settings/TileBoardSettingView.swift +++ b/T2iles/Sources/Views/Settings/TileBoardSettingView.swift @@ -53,13 +53,15 @@ struct TileBoardSettingView: View { .resizable() .aspectRatio(contentMode: .fit) .frame(height: previewSize.height) - .animation(nil) } .toggleStyle(CheckboxToggleStyle()) .foregroundColor(Color.primary.opacity(0.5)) .opacity(isSelected.wrappedValue ? 1.0 : 0.5) - .shadow(color: invertedBackgroundColor.opacity(0.5), radius: isSelected.wrappedValue ? 10 : 0) - .animation(.modalSpring) + .shadow( + color: invertedBackgroundColor.opacity(0.5), + radius: isSelected.wrappedValue ? 10 : 0 + ) + .animation(.modalSpring, value: isSelected.wrappedValue) .padding([.top, .bottom]) } } diff --git a/T2iles/Sources/Views/Side/CompositeSideView.swift b/T2iles/Sources/Views/Side/CompositeSideView.swift index 00723b7..b71d8b8 100644 --- a/T2iles/Sources/Views/Side/CompositeSideView.swift +++ b/T2iles/Sources/Views/Side/CompositeSideView.swift @@ -9,7 +9,6 @@ import SwiftUI struct CompositeSideView: View { - @Binding var selectedView: SelectedView @Binding var sideMenuViewState: CGSize @Binding var presentSideMenu: Bool @@ -24,7 +23,7 @@ struct CompositeSideView: View { .offset(x: presentSideMenu ? -(proxy.size.width / 2.0) : -(proxy.size.width + proxy.size.width / 2)) .offset(x: -sideMenuViewState.width) .rotation3DEffect(Angle(degrees: presentSideMenu ? Double(sideMenuViewState.width / 10) + 10 : 0), axis: (x: 0, y: 10, z: 0)) - .animation(.modalSpring) + .animation(.modalSpring, value: presentSideMenu) .gesture( DragGesture().onChanged { value in if value.translation.width < 0 { diff --git a/T2iles/Sources/Views/Side/SideMenuView.swift b/T2iles/Sources/Views/Side/SideMenuView.swift index a157b81..892eb62 100644 --- a/T2iles/Sources/Views/Side/SideMenuView.swift +++ b/T2iles/Sources/Views/Side/SideMenuView.swift @@ -34,14 +34,12 @@ struct SideMenuView: View { Group { VStack(spacing: interItemSpacing) { Spacer() - ForEach(0.. Date: Mon, 15 Aug 2022 21:08:31 +0300 Subject: [PATCH 2/3] Update the lang version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 299a3da..41b0f9f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # swiftui-2048[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) -[![Language](https://img.shields.io/badge/Language-Swift_5.5-orange.svg)]() +[![Language](https://img.shields.io/badge/Language-Swift_5.7-orange.svg)]() [![Framework](https://img.shields.io/badge/Framework-SwiftUI_3.0-red.svg)]() [![Shaders](https://img.shields.io/badge/Platforms-iOS|iPadOS|macOS-green.svg)]() [![Last Commit](https://img.shields.io/github/last-commit/jvirus/swiftui-2048)]() @@ -30,7 +30,7 @@ Please wait while the `.gif` files are loading... - Supports `iPhone`, `iPad` & `macOS`-enabled devices - No graphical assets - Minimum deployment target is `iOS 14.0` & `macOS 11.0` -- `Swift 5.3` +- `Swift 5.7` - Pure `SwiftUI 2.0` app - Score & merge streak system: when multiple merges occur in a row - you got a score multiplier 😎 - Settings From a701d3b433461f3ae26c5cd9c4b2021df16e28aa Mon Sep 17 00:00:00 2001 From: Astemir Eleev Date: Mon, 15 Aug 2022 21:08:57 +0300 Subject: [PATCH 3/3] Remove unused platform --- T2iles.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/T2iles.xcodeproj/project.pbxproj b/T2iles.xcodeproj/project.pbxproj index 026251f..91b1d1b 100644 --- a/T2iles.xcodeproj/project.pbxproj +++ b/T2iles.xcodeproj/project.pbxproj @@ -844,7 +844,9 @@ ); PRODUCT_BUNDLE_IDENTIFIER = eleev.astemir.T2iles; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -868,7 +870,9 @@ ); PRODUCT_BUNDLE_IDENTIFIER = eleev.astemir.T2iles; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; };