Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose placeholders #1095

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import android.text.style.SuggestionSpan
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.util.TypedValue
import android.view.DragEvent
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MotionEvent
Expand Down Expand Up @@ -254,6 +255,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
private var onVideoInfoRequestedListener: OnVideoInfoRequestedListener? = null
private var onAztecKeyListener: OnAztecKeyListener? = null
private var onVisibilityChangeListener: OnVisibilityChangeListener? = null
private var dragEventManager: DragEventManager? = null
var externalLogger: AztecLog.ExternalLogger? = null

private var isViewInitialized = false
Expand Down Expand Up @@ -356,6 +358,19 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
fun beforeMediaDeleted(attrs: AztecAttributes) {}
}

interface DragEventManager {
fun shouldProcessDragEvent(event: DragEvent?): Boolean
}

override fun onDragEvent(event: DragEvent?): Boolean {
val shouldProcessDragEvent = dragEventManager?.shouldProcessDragEvent(event)
if (shouldProcessDragEvent == true) {
return super.onDragEvent(event)
} else {
return false
}
}

/**
* Listens to keyboard events and calls the `shouldOverrideBackSpace` before each backspace event.
*/
Expand Down Expand Up @@ -1209,6 +1224,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
this.onVisibilityChangeListener = listener
}

fun setDragEventManager(listener: DragEventManager) {
this.dragEventManager = listener
}

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
onImeBackListener?.onImeBack()
Expand Down
10 changes: 10 additions & 0 deletions media-placeholders/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ android {
includeAndroidResources = true
}
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.14"
}
}

dependencies {
Expand All @@ -41,6 +47,10 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinCoroutinesVersion"
testImplementation "junit:junit:$jUnitVersion"
testImplementation "org.robolectric:robolectric:$robolectricVersion"
implementation 'androidx.compose.material3:material3:1.3.1'
implementation 'androidx.compose.foundation:foundation:1.7.5'
implementation 'androidx.compose.ui:ui:1.7.5'
implementation 'androidx.compose.ui:ui-tooling-preview:1.7.5'
}

dependencyAnalysis {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.wordpress.aztec.placeholders

import androidx.compose.runtime.Composable
import org.wordpress.aztec.AztecAttributes

interface ComposePlaceholderAdapter : PlaceholderManager.PlaceholderAdapter {
/**
* Use this method to draw the placeholder using Jetpack Compose.
* @param placeholderUuid the placeholder UUID
* @param attrs aztec attributes of the view
*/
@Composable
fun Placeholder(
placeholderUuid: String,
attrs: AztecAttributes,
)
}
Loading
Loading