From 092ed2fc212df7e868169ea499e47b70cd877ad8 Mon Sep 17 00:00:00 2001 From: Andrew Datsenko Date: Fri, 5 Apr 2024 14:08:53 -0700 Subject: [PATCH] //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 `. 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 --- .../ReactAndroid/api/ReactAndroid.api | 2 +- .../modules/sound/SoundManagerModule.java | 33 ------------------- .../react/modules/sound/SoundManagerModule.kt | 26 +++++++++++++++ 3 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index ac986f62f79..48d0cfa5267 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -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 (Lcom/facebook/react/bridge/ReactApplicationContext;)V public fun playTouchSound ()V } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.java deleted file mode 100644 index 67792f900d2..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.java +++ /dev/null @@ -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); - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.kt new file mode 100644 index 00000000000..df45543102d --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/sound/SoundManagerModule.kt @@ -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) + } +}