-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ios mute fix after discussion #296
Merged
Merged
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
249d977
ios mute button
64cf978
adjustment made based on dicsussion for Ios Mute button
fae9ad2
fixed the in the file
d76959f
changed name of file so the names are consistent
60bb06b
adjusted based on the other buttons
bd4b7f8
Clean up and fixes to get this ready
ianthetechie b71ea85
Use a boring ObservableObject and use UDF
ianthetechie 35df836
Simplified and tested mute button:
Archdoog 583acea
Delete .gitmodules
ianthetechie 45ee6c8
Delete extraneous submodule
ianthetechie 10c83d9
Try to fix CI
ianthetechie d64dd25
Attempt to improve UI responsiveness
ianthetechie f93e9e1
Improve speed limit display
ianthetechie 4c284a2
Hide when not navigating
ianthetechie 1d3cc67
Add missing docs
ianthetechie 57e6f89
Swiftformat
ianthetechie 7e01782
Update snapshots
ianthetechie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
29 changes: 29 additions & 0 deletions
29
apple/Sources/FerrostarSwiftUI/Views/Controls/MuteUIButton.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,29 @@ | ||
import SwiftUI | ||
|
||
public struct MuteUIButton: View { | ||
@Binding public var isMuted: Bool | ||
|
||
public init(isMuted: Binding<Bool>) { | ||
self._isMuted = isMuted | ||
} | ||
|
||
public var body: some View { | ||
Button(action: { | ||
isMuted.toggle() | ||
}) { | ||
Image(systemName: isMuted ? "speaker.slash.fill" : "speaker.2.fill") | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
.frame(width: 18, height: 18) | ||
.padding() | ||
.foregroundColor(.black) | ||
.background(Color.white) | ||
.clipShape(Circle()) | ||
.shadow(radius: 10) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
MuteUIButton(isMuted: .constant(false)) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look quite right, but it's probably a result of our
AVSpeechSpokenInstructionObserver
. That class doesn't really have a good way to publish the isMuted value.Here's an updated version which you could copy & replace to the
apple/Sources/FerrostarCore/Speech.swift
file:I'd be happy to also post a PR with this change if that'd help.
The key difference is the
AVSpeechSpokenInstructionObserver
will actually have an isMuted publisher on it that's designed to be used in a SwiftUI instead of a simple bool. A simple bool won't trigger updates to the button, causing the problem you were probably hoping to solve with@State
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is tricky. You're right that the current protocol isn't going to just drop in to a SwiftUI setup.... but I'm not sure this actually fixes the problem 😅 It handles one half (publishing updates), but it doesn't actually get us to a two-way binding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a SwiftUI app, I would not expect a
@Binding var
to actually alter the behavior of a service even though you're correct that it offers a two way street which could be used for that. Having a bespokefunc setMute(_ mute: Bool)
and a published state that SwiftUI can easily use seems to capture the best of a button running a behavior and a state being published for the visual UI.A get set pattern was nice, but in this case seems like the wrong solution given the goals and SwiftUI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I see your point. Though I think
@Binding
is at least somewhat intended for this purpose.The problem I hit with the method-based approach, which is how you'd do it in Jetpack Compose to preserve UDF, is that things get extremely messy with the Swift type system.
At A high level, here's what I think you're suggesting:
SpokenInstructionObserver
:isMuted
get-onlyfunc setMuted(...)
MuteUIButton
:@Binding
to@ObservedObject
and observe theSpokenInstructionObserver
directlyspokenInstructionObserver.setMuted(...)
spokenInstructionObserver.isMuted
is published, observe that value in the image composition rather than the bindingIn order to use a
@Published
property and observe the object directly, we would need to makeSpokenInstructionObserver
conform toObservableObject
. This sounds trivial, but this opens up Pandora's box with errors likeType 'any SpokenInstructionObserver' cannot conform to 'ObservableObject'
that highlight the flaws of the Swift type system...I am unable to find a resolution to this at the moment. Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay... after banging my head against the wall a bit more, I think I have something that works. It's nominally better... Have a look over it and lemme know what you think. I don't really like the way it forces us to include generic bounds. And I couldn't get it to work with an optional
T
in the constructor, since the desirable default,nil
is going to have an unknown type 😂 Andany
types don't work as noted. So, the only option remaining that seems to work OK is to define a dummy default, which you can override.