Skip to content

Commit

Permalink
Merge pull request #1095 from wordpress-mobile/feature/compose-placeh…
Browse files Browse the repository at this point in the history
…olders

Compose placeholders
  • Loading branch information
planarvoid authored Jan 23, 2025
2 parents 806c3a4 + b7768e3 commit f749d3b
Show file tree
Hide file tree
Showing 9 changed files with 1,272 additions and 570 deletions.
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

0 comments on commit f749d3b

Please sign in to comment.