OXYGENHUB
# 5edf011e4d10 oxygenhub-android / app / src / main / java / com / example / oxygenhub / MainActivity.kt
1.4 KiB · last changed Android: Hook up Rust FFI greeting to Compose UI 1 month ago source blame history raw
e0e4a1c4 Andy McCall ↶ 1
package com.example.oxygenhub
2
3
import android.os.Bundle
4
import androidx.activity.ComponentActivity
5
import androidx.activity.compose.setContent
6
import androidx.activity.enableEdgeToEdge
7
import androidx.compose.foundation.layout.fillMaxSize
8
import androidx.compose.foundation.layout.padding
9
import androidx.compose.material3.Scaffold
10
import androidx.compose.material3.Text
11
import androidx.compose.runtime.Composable
12
import androidx.compose.ui.Modifier
13
import androidx.compose.ui.tooling.preview.Preview
14
import com.example.oxygenhub.ui.theme.OxygenHubTheme
15
5edf011e Andy McCall ↶ 16
import uniffi.rust_core.oxygenGreeting
17
e0e4a1c4 Andy McCall ↶ 18
class MainActivity : ComponentActivity() {
19
    override fun onCreate(savedInstanceState: Bundle?) {
20
        super.onCreate(savedInstanceState)
21
        enableEdgeToEdge()
22
        setContent {
23
            OxygenHubTheme {
24
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
25
                    Greeting(
5edf011e Andy McCall ↶ 26
                        name = "Oxygen",
e0e4a1c4 Andy McCall ↶ 27
                        modifier = Modifier.padding(innerPadding)
28
                    )
29
                }
30
            }
31
        }
32
    }
33
}
34
35
@Composable
36
fun Greeting(name: String, modifier: Modifier = Modifier) {
37
    Text(
5edf011e Andy McCall ↶ 38
        text = oxygenGreeting(name),
e0e4a1c4 Andy McCall ↶ 39
        modifier = modifier
40
    )
41
}
42
43
@Preview(showBackground = true)
44
@Composable
45
fun GreetingPreview() {
46
    OxygenHubTheme {
47
        Greeting("Android")
48
    }
49
}