Skip to content

Commit 99710bf

Browse files
Merge pull request #131 from FleksySDK/francesc/add_inapp_compose_example
sample: add inapp text field using compose
2 parents cebaa22 + 962b25d commit 99710bf

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

Examples/InAppKeyboard/android/InAppkeyboardAdvanced/app/build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ android {
3636

3737
buildFeatures {
3838
viewBinding = true
39+
compose = true
40+
}
41+
42+
composeOptions {
43+
kotlinCompilerExtensionVersion = "1.5.11"
3944
}
4045
}
4146

@@ -48,7 +53,12 @@ dependencies {
4853
implementation("androidx.navigation:navigation-fragment-ktx:2.7.7")
4954
implementation("androidx.navigation:navigation-ui-ktx:2.7.7")
5055

51-
implementation("co.thingthing.fleksycore:fleksycore-release:4.7.2")
56+
implementation("co.thingthing.fleksycore:fleksycore-release:4.9.0")
57+
58+
val composeBom = platform("androidx.compose:compose-bom:2024.04.01")
59+
implementation(composeBom)
60+
androidTestImplementation(composeBom)
61+
implementation("androidx.compose.material3:material3")
5262

5363
testImplementation("junit:junit:4.13.2")
5464
androidTestImplementation("androidx.test.ext:junit:1.1.5")

Examples/InAppKeyboard/android/InAppkeyboardAdvanced/app/src/main/java/com/fleksy/inappkeyboardadvanced/views/HostFragment.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,36 @@ import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
7+
import androidx.compose.foundation.layout.fillMaxSize
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.material3.Text
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.res.stringResource
13+
import androidx.compose.ui.unit.dp
14+
import androidx.compose.ui.viewinterop.AndroidView
715
import androidx.fragment.app.DialogFragment
816
import androidx.fragment.app.Fragment
17+
import co.thingthing.fleksy.core.keyboard.inapp.FleksyEditText
918
import co.thingthing.fleksy.core.keyboard.inapp.InAppFragmentListener
19+
import com.fleksy.inappkeyboardadvanced.R
1020
import com.fleksy.inappkeyboardadvanced.databinding.FragmentHostBinding
1121

22+
@Composable
23+
fun ComposeFleksyTextField(inAppFragmentListener: InAppFragmentListener) {
24+
val editHint = stringResource(id = R.string.try_this_edittext)
25+
AndroidView(
26+
factory = { context ->
27+
val edit = FleksyEditText(context)
28+
edit.hint = editHint
29+
edit
30+
},
31+
update = {
32+
inAppFragmentListener.registerEditText(it, null)
33+
}
34+
)
35+
}
36+
1237
class HostFragment : Fragment() {
1338

1439
private lateinit var binding: FragmentHostBinding
@@ -29,6 +54,10 @@ class HostFragment : Fragment() {
2954
inAppFragmentListener = requireActivity() as InAppFragmentListener
3055
inAppFragmentListener.onCreate()
3156

57+
binding.composeView.setContent {
58+
ComposeFleksyTextField(inAppFragmentListener)
59+
}
60+
3261
setupButtons()
3362
}
3463

Examples/InAppKeyboard/android/InAppkeyboardAdvanced/app/src/main/res/layout/fragment_host.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@
1414
android:imeOptions="actionDone"
1515
android:inputType="textCapSentences|text"
1616
android:singleLine="true"
17-
app:layout_constraintBottom_toBottomOf="parent"
18-
app:layout_constraintEnd_toEndOf="parent"
1917
app:layout_constraintStart_toStartOf="parent"
20-
app:layout_constraintTop_toTopOf="parent" />
18+
app:layout_constraintEnd_toEndOf="parent"
19+
app:layout_constraintTop_toTopOf="parent"
20+
app:layout_constraintBottom_toTopOf="@+id/compose_view"/>
21+
22+
<androidx.compose.ui.platform.ComposeView
23+
android:id="@+id/compose_view"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:layout_marginStart="16dp"
27+
android:layout_marginEnd="16dp"
28+
app:layout_constraintTop_toBottomOf="@+id/tryEditText"
29+
app:layout_constraintBottom_toTopOf="@+id/btBottomSheet"/>
2130

2231
<Button
2332
android:id="@+id/btBottomSheet"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
33
id("com.android.application") version "8.2.1" apply false
4-
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
4+
id("org.jetbrains.kotlin.android") version "1.9.23" apply false
55
}

0 commit comments

Comments
 (0)