-
Notifications
You must be signed in to change notification settings - Fork 177
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
Android: option to vibrate on button press #580
base: main
Are you sure you want to change the base?
Conversation
runtimes/web/src/ui/app.ts
Outdated
@@ -76,6 +83,11 @@ export class App extends LitElement { | |||
|
|||
private readonly diskPrefix: string; | |||
|
|||
private vibrateLevelIdx = 0; |
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.
I wasn't sure where to store the vibration level. I tried in virtual-gamepad.ts at first, but didn't see how menu-overlay.ts could access it, so it ended up here.
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.
I'm defaulting to "OFF" for now, but if feedback is positive I recommend we default to "MEDIUM", I think the vibration really makes it feel more tactile.
@@ -115,6 +118,7 @@ export class MenuOverlay extends LitElement { | |||
|
|||
@state() private selectedIdx = 0; | |||
@state() private netplaySummary: { playerIdx: number, ping: number }[] = []; | |||
@state() private vibrateLevel = ""; |
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.
I tried just referencing app.vibrateLevel, but wasn't seeing render updates immediately. Is this the correct pattern? Mirror the setting in a local @state()
variable?
runtimes/web/src/ui/menu-overlay.ts
Outdated
@@ -243,11 +258,16 @@ export class MenuOverlay extends LitElement { | |||
} | |||
|
|||
render () { | |||
if (!this.vibrateLevel) { | |||
this.vibrateLevel = this.app.vibrateLevel[0]; |
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.
I tried setting this in the constructor, but looks like app
is not yet ready, so moved it to here.
Hmm, after some further testing it seems like the vibration stops working after a while. Maybe chrome blocks website vibrations if they are triggered too frequently? |
Was testing this for a while tonight on a Samsung Galaxy S21, no issues this time. Tried testing on an iPhone 13 as well, as intended there was no "vibrate" menu option. |
Thanks so much for the PR! It looks very clean, and this is a great feature. Some feedback/questions after testing:
|
Very interesting. On my Samsung Galaxy S21, the different vibration do feel different, but it probably depends on the device. The way I have it now, "LOW" should be 1 millisecond of vibration, "MEDIUM" 2, and "HIGH" 4. Maybe I should have more like 10 different levels of vibration, from 1ms to 1024ms?
Yeah, I started out just vibrating on touchdown, but after playing a bunch of games, it just didn't feel right to me, and vibrate both felt more right.
Sure.
Yeah, that makes sense. |
I haven't made a OSS contribution in a while, and web stuff is not my expertise, so any feedback is appreciated!