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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Libraries/Components/Touchable/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
const BoundingDimensions = require('BoundingDimensions');
const Position = require('Position');
const React = require('React'); // eslint-disable-line no-unused-vars
const ReactNative = require('ReactNative');
const TouchEventUtils = require('fbjs/lib/TouchEventUtils');
const View = require('View');
const UIManager = require('UIManager');
const Platform = require('Platform');

const keyMirror = require('fbjs/lib/keyMirror');
const normalizeColor = require('normalizeColor');
Expand Down Expand Up @@ -712,12 +715,23 @@ var TouchableMixin = {

var shouldInvokePress = !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
if (shouldInvokePress && this.touchableHandlePress) {
if (Platform.OS === 'android') {
this._playClickSound();
}
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".

_playClickSound: function() {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.RCTView.Commands.playClickSound,
null
);
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import android.graphics.Rect;
import android.os.Build;
import android.view.SoundEffectConstants;
import android.view.View;

import com.facebook.csslayout.CSSConstants;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class ReactViewManager extends ViewGroupManager<ReactViewGroup> {
};
private static final int CMD_HOTSPOT_UPDATE = 1;
private static final int CMD_SET_PRESSED = 2;
private static final int CMD_PLAY_CLICK_SOUND = 3;

@ReactProp(name = "accessible")
public void setAccessible(ReactViewGroup view, boolean accessible) {
Expand Down Expand Up @@ -158,7 +160,10 @@ public ReactViewGroup createViewInstance(ThemedReactContext context) {

@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("hotspotUpdate", CMD_HOTSPOT_UPDATE, "setPressed", CMD_SET_PRESSED);
return MapBuilder.of(
"hotspotUpdate", CMD_HOTSPOT_UPDATE,
"setPressed", CMD_SET_PRESSED,
"playClickSound", CMD_PLAY_CLICK_SOUND);
}

@Override
Expand All @@ -184,6 +189,10 @@ public void receiveCommand(ReactViewGroup root, int commandId, @Nullable Readabl
root.setPressed(args.getBoolean(0));
break;
}
case CMD_PLAY_CLICK_SOUND: {
root.playSoundEffect(SoundEffectConstants.CLICK);
break;
}
}
}

Expand Down