forked from mlemgroup/mlem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pro tem tab reselection (mlemgroup#769)
- Loading branch information
1 parent
baa54a8
commit 35cdbfe
Showing
11 changed files
with
111 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Mlem/Custom Tab Bar/FancyTabBarReselectionEnvironmentKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// FancyTabBarReselectionEnvironmentKey.swift | ||
// Mlem | ||
// | ||
// Created by Eric Andrews on 2023-11-02. | ||
// | ||
import Foundation | ||
import SwiftUI | ||
|
||
struct FancyTabBarReselectionEnvironmentKey: EnvironmentKey { | ||
static var defaultValue: Int? { nil } | ||
} | ||
|
||
extension EnvironmentValues { | ||
var tabReselectionHashValue: Int? { | ||
get { self[FancyTabBarReselectionEnvironmentKey.self] } | ||
set { self[FancyTabBarReselectionEnvironmentKey.self] = newValue } | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
Mlem/Custom Tab Bar/FancyTabNavigationSelectionHashValueEnvironmentKey.swift
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
Mlem/Extensions/View Modifiers/View+TabReselectionConsumer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// View+TabReselectionConsumer.swift | ||
// Mlem | ||
// | ||
// Created by Eric Andrews on 2023-11-04. | ||
// | ||
import Foundation | ||
import SwiftUI | ||
|
||
struct ReselectConsumer: ViewModifier { | ||
@Environment(\.tabReselectionHashValue) private var tabReselectionHashValue | ||
|
||
let tab: TabSelection | ||
let action: () -> Void | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.onChange(of: tabReselectionHashValue) { newValue in | ||
if newValue == tab.hashValue { | ||
action() | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func reselectAction(tab: TabSelection, action: @escaping () -> Void) -> some View { | ||
modifier(ReselectConsumer(tab: tab, action: action)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.