Created
April 9, 2021 14:35
-
-
Save tkuenneth/8e9fb278e898c0ec6d46fbcb925b8c40 to your computer and use it in GitHub Desktop.
Short demo for OnReceiveContentListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.thomaskuenneth.sandbox | |
import android.os.Bundle | |
import android.widget.EditText | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.material.* | |
import androidx.compose.runtime.* | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.text.input.TextFieldValue | |
import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.unit.dp | |
import androidx.compose.ui.viewinterop.AndroidView | |
import androidx.core.view.ViewCompat | |
import com.thomaskuenneth.sandbox.ui.theme.SandboxTheme | |
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
SandboxTheme { | |
Surface(color = MaterialTheme.colors.background) { | |
Sandbox() | |
} | |
} | |
} | |
} | |
} | |
@Composable | |
@Preview(showBackground = true) | |
fun Sandbox() { | |
var current by remember { mutableStateOf(TextFieldValue()) } | |
Scaffold { | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.padding(16.dp) | |
) { | |
TextField(value = current, | |
modifier = Modifier.fillMaxWidth(), | |
placeholder = { Text("composable") }, | |
onValueChange = { | |
current = it | |
} | |
) | |
AndroidView( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(top = 16.dp), | |
factory = { context -> | |
EditText(context).apply { | |
hint = "Hello platform" | |
setOnReceiveContentListener( | |
arrayOf("text/*") | |
) { _, payload -> | |
println("Hello platform") | |
payload | |
} | |
} | |
} | |
) | |
AndroidView( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(top = 16.dp), | |
factory = { context -> | |
EditText(context).apply { | |
hint = "Hello androidx" | |
ViewCompat.setOnReceiveContentListener(this, arrayOf("text/*")) | |
{ _, payload -> | |
println("Hello androidx") | |
payload | |
} | |
} | |
} | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment