//xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound:soundAndroid (#43860)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43860

Changelog: [Internal]
_____

## Why?
We recommend to use Kotlin for any new code and are actively migrating Java code to Kotlin. This codemod service attempts to migrate existing Java code to Kotlin.

## How was this diff generated?
This codemod service scans through qualified paths and looks for Java modules. Then it runs `kotlinator.sh` on each module, which generated this diff.

## What if I see problems in this diff?
We recommend commandeering and fixing the diff. If you reject or abandon the diff, the codemod service will regenerate it in a few days
- Script for easily commandeer & open diff: In fbandroid, `scripts/commandeer_and_checkout.sh <DIFF>`. It not only commandeer the diff, but also rebase & open diff in Android Studio.
- Report repeating issues in [Kotlinator Papercut](https://fburl.com/papercuts/1g4f4qas)

See more useful tips & scripts in [Kotlin Auto-Conversion Codemod Wiki](https://fburl.com/wiki/c68ka0pu)

_____

## Questions / Comments / Feedback?

**Your feedback is important to us! Give feedback about this diff by clicking the "Provide Feedback" button below.**

* Returning back to author or abandoning this diff will only cause the diff to be regenerated in the future.
* Do **NOT** post in the CodemodService Feedback group about this specific diff.

_____

## Codemod Metadata

NOTE: You won't need to read this section to review this diff.

https://www.internalfb.com/intern/sandcastle/job/1239557953/

|Oncall|[kotlin_in_fb4a](https://our.intern.facebook.com/intern/oncall3/?shortname=kotlin_in_fb4a)|
|CodemodConfig|[fbsource/kotlinator.json](https://www.internalfb.com/codemod_service/fbsource%2Fkotlinator.json)|
|ConfigType|configerator|

Rules run:
- CodemodTransformerFBSourceScript

This diff was created with [CodemodService](https://fburl.com/CodemodService).

Reviewed By: cortinico

Differential Revision: D55725322

fbshipit-source-id: 8f78d221a8f04136019055a6ea64d8ec05bfd8a2
This commit is contained in:
Andrew Datsenko
2024-04-05 14:08:53 -07:00
committed by Facebook GitHub Bot
parent 5cf4f25d96
commit 092ed2fc21
3 changed files with 27 additions and 34 deletions
@@ -3471,7 +3471,7 @@ public class com/facebook/react/modules/share/ShareModule : com/facebook/fbreact
public fun share (Lcom/facebook/react/bridge/ReadableMap;Ljava/lang/String;Lcom/facebook/react/bridge/Promise;)V
}
public class com/facebook/react/modules/sound/SoundManagerModule : com/facebook/fbreact/specs/NativeSoundManagerSpec {
public final class com/facebook/react/modules/sound/SoundManagerModule : com/facebook/fbreact/specs/NativeSoundManagerSpec {
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
public fun playTouchSound ()V
}
@@ -1,33 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.modules.sound;
import android.content.Context;
import android.media.AudioManager;
import com.facebook.fbreact.specs.NativeSoundManagerSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;
/** {@link NativeModule} that allows Playing device sounds from JS. */
@ReactModule(name = NativeSoundManagerSpec.NAME)
public class SoundManagerModule extends NativeSoundManagerSpec {
public SoundManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public void playTouchSound() {
AudioManager audioManager =
(AudioManager) getReactApplicationContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) {
audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
}
}
}
@@ -0,0 +1,26 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.modules.sound
import android.content.Context
import android.media.AudioManager
import com.facebook.fbreact.specs.NativeSoundManagerSpec
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.annotations.ReactModule
/** [NativeModule] that allows Playing device sounds from JS. */
@ReactModule(name = NativeSoundManagerSpec.NAME)
public class SoundManagerModule(reactContext: ReactApplicationContext?) :
NativeSoundManagerSpec(reactContext) {
public override fun playTouchSound() {
val audioManager =
getReactApplicationContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK)
}
}