Skip to content
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 click sounds on press #6825

Closed

Conversation

mikemonteith
Copy link

Android should play a sound effect on click by default.
Since the ReactNative touch event model circumvents the usual Android OnClickListener, we trigger the click sound manually.

this.touchableHandlePress(e);
}
}

this.touchableDelayTimeout && clearTimeout(this.touchableDelayTimeout);
this.touchableDelayTimeout = null;
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyword-spacing: Expected space(s) after "if".

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @sahrens and @kmagiera to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Apr 5, 2016
@facebook-github-bot
Copy link
Contributor

@mikemonteith updated the pull request.

@ghost
Copy link

ghost commented Apr 30, 2016

@sahrens would you mind taking a look at this pull request? It's been a while since the last commit was reviewed.

@sahrens
Copy link
Contributor

sahrens commented Apr 30, 2016

Nice, but I doubt all apps want this - can you add a global config to turn it off? Like Touchable.DISABLE_DEFAULT_SOUNDS that people can set when there app first initializes, and a comment in the docs? cc @dmmiller and @mkonicek for thoughts.

For the propTypes, does it work to factor them out into a shared class, TouchablePropTypes? Make sure that if there are legit differences between the same propType docs on different touchables that those differences are preserved.

Also, please rebase and fix the conflicts and get tests passing.

@satya164
Copy link
Contributor

satya164 commented May 1, 2016

It's rare for apps in Android to play a sound on touch. So I'd say it should be off by default.

@mikemonteith
Copy link
Author

@satya164 @sahrens if you turn on system sounds in android sound settings you'll notice that almost all apps play a click sound on touch, as its default onClick handler behaviour. (I think almost everyone has system sounds turned off for this reason)

@satya164
Copy link
Contributor

satya164 commented May 1, 2016

@mikemonteith Ah. Weird.

@janicduplessis
Copy link
Contributor

janicduplessis commented May 16, 2016

Tested a few apps on Android and every touchable element always produces a sound so I think this should be enabled by default and not even be a prop. It's up to the user to enable / disable touch sounds but apps should not decide whether or not there should be one.

Also right now react native apps touch sounds are inconsistent since touchable elements don't produce sounds but other native controls like Toolbar buttons do.

@mkonicek
Copy link
Contributor

mkonicek commented May 16, 2016

Tested a few apps on Android and every touchable element always produces a sound

@janicduplessis You're right, as long as it's enabled in the system settings. On my Nexus 5X I actually had sounds disabled in Settings -> Sounds & notifications -> Other sounds -> Touch sounds. Now when I enabled it all touchables produce a sound, as long as the media volume is not muted.

@mikemonteith Let's play the sounds by default, agree with @janicduplessis we don't need the prop, as long as the behavior respects the system setting.

@ide
Copy link
Contributor

ide commented May 16, 2016

Also right now react native apps touch sounds are inconsistent since touchable elements don't produce sounds but other native controls like Toolbar buttons do.

Is there a way we could cleanly fake this? Ex: by calling into an audio library directly, or sending fake touch events to a single offscreen button?

@janicduplessis
Copy link
Contributor

@ide I'm pretty sure this PR does exactly what we want by calling https://developer.android.com/reference/android/view/View.html#playSoundEffect(int)

@mikemonteith
Copy link
Author

Looks like there's some interest in this PR. Would you like me to make any changes to it?

@janicduplessis
Copy link
Contributor

@mikemonteith Yes, could you remove the prop you added and always play the touch sounds, could you also make sure it repects the system setting for touch sounds.

@facebook-github-bot
Copy link
Contributor

@mikemonteith updated the pull request.

@@ -712,12 +714,21 @@ var TouchableMixin = {

var shouldInvokePress = !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
if (shouldInvokePress && this.touchableHandlePress) {
this._playClickSound();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called on iOS as well as Android. Is that intentional?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it should just be android. Should I add a Platform.os === 'android' check here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably add the platform check to make sure it doesn't do unnecessary stuff on ios.

@mkonicek
Copy link
Contributor

Thanks for updating the pull request @mikemonteith 👍 I added one question.

Can you please add a test plan demonstrating the system setting is respected (you can hear sounds if and only if this is enabled in system settings)?
For an explanation of what a test plan is, see https://github.com/facebook/react-native/blob/master/PULL_REQUEST_TEMPLATE.md

@dmmiller
Copy link

@facebook-github-bot shipit

@ghost ghost added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Jul 20, 2016
@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review internal test results.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 20, 2016
@dmmiller
Copy link

Tried importing and this is failing on some internal tests. The problem is that you call findNodeHandle on things that might not end up in the tree. In particular, it is failing on a test like this :

<Text style={styles.centeredText} onPress={this.handlePress.bind(this, 'text2')}>
          <Text onPress={this.handlePress.bind(this, 'nested1')}>link</Text>
          {' text '}
          <Text onPress={this.handlePress.bind(this, 'nested2')}>link</Text>
</Text>

Try clicking on one of the nested text pieces. This fires an event on a virtual node which you then dispatch on. That doesn't actually exist in the tree. I think you can get around this by perhaps just always passing the root or something.

@ghost
Copy link

ghost commented Jul 20, 2016

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

@ghost ghost added Import Failed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Jul 20, 2016
@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 4, 2016
@gousta
Copy link

gousta commented Aug 6, 2016

Hi, any updates on this?

@mkonicek
Copy link
Contributor

mkonicek commented Sep 9, 2016

@mikemonteith I'm going through all pull requests and noticed this one hasn't been updated in a while and the last comment requests changes. I'll close this pull request so it doesn't stay open indefinitely but please send a new one if you want to continue working on this.

I think this is useful! If anyone wants to send a new PR with this code, addressing the comment about findNodeHandle failing tests by @dmmiller it would be cool to get this in!

@deehuey
Copy link

deehuey commented Sep 22, 2017

Hey guys, why did we not implement this? It's driving me crazy as a new react-native user. It totally pulls me away from the 'native' feeling.

@bcalik
Copy link
Contributor

bcalik commented Oct 9, 2017

I can't believe this issue is still not fixed for years.

@deehuey
Copy link

deehuey commented Oct 9, 2017 via email

@mikemonteith
Copy link
Author

Hi. I haven't worked on a react-native project for over a year now so this is very low on my priority list. The pull request is so old that I'm sure it needs to be looked at anew.

Hopefully someone else can pick this up before I eventually get round to looking at it again.

facebook-github-bot pushed a commit that referenced this pull request Apr 10, 2018
Summary:
Android apps play a touch sound on press, as long as you have "Touch sounds" enabled in the settings. As and Android user, when building my app using React Native, one of the first things I noticed was that there were not any touch sounds. This is missing from React Native and there have been multiple PRs to have this implemented, but no success.

This PR iterates over [#6825](#6825) and [#11136](#11136)

This PR keeps it simple by only implementing the enhancement for Android, as iOS apps typically do not use touch sounds, and follows the users' system settings for whether or not the sound is played.

I have manually tested this on multiple devices and emulators with zero problems

[ANDROID] [ENHANCEMENT] [UIManagerModule.java]- Adds Android click sound to touchables

[ANDROID] [ENHANCEMENT] [Touchable] - Adds Android click sound to touchables
Closes #17183

Differential Revision: D7560327

Pulled By: hramos

fbshipit-source-id: ce1094c437541bc677c7d64b0dba343dd9574422
campsafari pushed a commit to exozet/react-native that referenced this pull request Apr 11, 2018
Summary:
Android apps play a touch sound on press, as long as you have "Touch sounds" enabled in the settings. As and Android user, when building my app using React Native, one of the first things I noticed was that there were not any touch sounds. This is missing from React Native and there have been multiple PRs to have this implemented, but no success.

This PR iterates over [facebook#6825](facebook#6825) and [facebook#11136](facebook#11136)

This PR keeps it simple by only implementing the enhancement for Android, as iOS apps typically do not use touch sounds, and follows the users' system settings for whether or not the sound is played.

I have manually tested this on multiple devices and emulators with zero problems

[ANDROID] [ENHANCEMENT] [UIManagerModule.java]- Adds Android click sound to touchables

[ANDROID] [ENHANCEMENT] [Touchable] - Adds Android click sound to touchables
Closes facebook#17183

Differential Revision: D7560327

Pulled By: hramos

fbshipit-source-id: ce1094c437541bc677c7d64b0dba343dd9574422
LukeDurrant pushed a commit to LukeDurrant/react-native that referenced this pull request Apr 11, 2018
Summary:
Android apps play a touch sound on press, as long as you have "Touch sounds" enabled in the settings. As and Android user, when building my app using React Native, one of the first things I noticed was that there were not any touch sounds. This is missing from React Native and there have been multiple PRs to have this implemented, but no success.

This PR iterates over [facebook#6825](facebook#6825) and [facebook#11136](facebook#11136)

This PR keeps it simple by only implementing the enhancement for Android, as iOS apps typically do not use touch sounds, and follows the users' system settings for whether or not the sound is played.

I have manually tested this on multiple devices and emulators with zero problems

[ANDROID] [ENHANCEMENT] [UIManagerModule.java]- Adds Android click sound to touchables

[ANDROID] [ENHANCEMENT] [Touchable] - Adds Android click sound to touchables
Closes facebook#17183

Differential Revision: D7560327

Pulled By: hramos

fbshipit-source-id: ce1094c437541bc677c7d64b0dba343dd9574422
LukeDurrant pushed a commit to LukeDurrant/react-native that referenced this pull request Apr 11, 2018
Summary:
Android apps play a touch sound on press, as long as you have "Touch sounds" enabled in the settings. As and Android user, when building my app using React Native, one of the first things I noticed was that there were not any touch sounds. This is missing from React Native and there have been multiple PRs to have this implemented, but no success.

This PR iterates over [facebook#6825](facebook#6825) and [facebook#11136](facebook#11136)

This PR keeps it simple by only implementing the enhancement for Android, as iOS apps typically do not use touch sounds, and follows the users' system settings for whether or not the sound is played.

I have manually tested this on multiple devices and emulators with zero problems

[ANDROID] [ENHANCEMENT] [UIManagerModule.java]- Adds Android click sound to touchables

[ANDROID] [ENHANCEMENT] [Touchable] - Adds Android click sound to touchables
Closes facebook#17183

Differential Revision: D7560327

Pulled By: hramos

fbshipit-source-id: ce1094c437541bc677c7d64b0dba343dd9574422
bunnyc1986 pushed a commit to bunnyc1986/react-native that referenced this pull request May 11, 2018
Summary:
Android apps play a touch sound on press, as long as you have "Touch sounds" enabled in the settings. As and Android user, when building my app using React Native, one of the first things I noticed was that there were not any touch sounds. This is missing from React Native and there have been multiple PRs to have this implemented, but no success.

This PR iterates over [facebook#6825](facebook#6825) and [facebook#11136](facebook#11136)

This PR keeps it simple by only implementing the enhancement for Android, as iOS apps typically do not use touch sounds, and follows the users' system settings for whether or not the sound is played.

I have manually tested this on multiple devices and emulators with zero problems

[ANDROID] [ENHANCEMENT] [UIManagerModule.java]- Adds Android click sound to touchables

[ANDROID] [ENHANCEMENT] [Touchable] - Adds Android click sound to touchables
Closes facebook#17183

Differential Revision: D7560327

Pulled By: hramos

fbshipit-source-id: ce1094c437541bc677c7d64b0dba343dd9574422
macdoum1 pushed a commit to macdoum1/react-native that referenced this pull request Jun 28, 2018
Summary:
Android apps play a touch sound on press, as long as you have "Touch sounds" enabled in the settings. As and Android user, when building my app using React Native, one of the first things I noticed was that there were not any touch sounds. This is missing from React Native and there have been multiple PRs to have this implemented, but no success.

This PR iterates over [facebook#6825](facebook#6825) and [facebook#11136](facebook#11136)

This PR keeps it simple by only implementing the enhancement for Android, as iOS apps typically do not use touch sounds, and follows the users' system settings for whether or not the sound is played.

I have manually tested this on multiple devices and emulators with zero problems

[ANDROID] [ENHANCEMENT] [UIManagerModule.java]- Adds Android click sound to touchables

[ANDROID] [ENHANCEMENT] [Touchable] - Adds Android click sound to touchables
Closes facebook#17183

Differential Revision: D7560327

Pulled By: hramos

fbshipit-source-id: ce1094c437541bc677c7d64b0dba343dd9574422
react-one pushed a commit to react-one/react-native that referenced this pull request Sep 24, 2021
Memo check compared elements of prevProps to nextProps but failed
to take new props into account. Fixed the logic and added a new
test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.