Skip to content

Commit

Permalink
//xplat/js/react-native-github/packages/react-native/ReactAndroid/src…
Browse files Browse the repository at this point in the history
…/main/java/com/facebook/react/modules/clipboard:clipboardAndroid (#43861)

Summary:
Pull Request resolved: #43861

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/22517999373069959/

|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: D55725451
  • Loading branch information
andrewdacenko authored and facebook-github-bot committed Apr 8, 2024
1 parent 3422dcf commit 6efc4fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -3041,7 +3041,7 @@ public class com/facebook/react/modules/camera/ImageStoreManager : com/facebook/
public fun getBase64ForTag (Ljava/lang/String;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V
}

public class com/facebook/react/modules/clipboard/ClipboardModule : com/facebook/fbreact/specs/NativeClipboardSpec {
public final class com/facebook/react/modules/clipboard/ClipboardModule : com/facebook/fbreact/specs/NativeClipboardSpec {
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
public fun getString (Lcom/facebook/react/bridge/Promise;)V
public fun setString (Ljava/lang/String;)V
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.clipboard

import android.content.ClipData
import android.content.ClipboardManager
import com.facebook.fbreact.specs.NativeClipboardSpec
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.annotations.ReactModule

/** A module that allows JS to get/set clipboard contents. */
@ReactModule(name = NativeClipboardSpec.NAME)
public class ClipboardModule(context: ReactApplicationContext) : NativeClipboardSpec(context) {

private val clipboardService: ClipboardManager
get() =
getReactApplicationContext().getSystemService(ReactApplicationContext.CLIPBOARD_SERVICE)
as ClipboardManager

public override fun getString(promise: Promise) {
try {
val clipboard = clipboardService
val clipData = clipboard.primaryClip
if (clipData != null && clipData.itemCount >= 1) {
val firstItem = clipData.getItemAt(0)
promise.resolve("${firstItem.text}")
} else {
promise.resolve("")
}
} catch (e: Exception) {
promise.reject(e)
}
}

public override fun setString(text: String?) {
val clipdata: ClipData = ClipData.newPlainText(null, text)
clipboardService.setPrimaryClip(clipdata)
}
}

0 comments on commit 6efc4fd

Please sign in to comment.