Skip to content

Commit

Permalink
Add setMinDurationBetweenContentChangesMillis
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Powolny authored and facebook-github-bot committed Nov 4, 2024
1 parent d86656a commit 18cf1e4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions litho-core/src/main/java/com/facebook/litho/CommonProps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ class CommonProps : LayoutProps, Equivalence<CommonProps?> {
val screenReaderFocusable: Boolean
get() = _nodeInfo?.screenReaderFocusState == NodeInfo.SCREEN_READER_FOCUS_SET_TRUE

fun setMinDurationBetweenContentChangesMillis(duration: Long) {
getOrCreateNodeInfo().minDurationBetweenContentChangesMillis = duration
}

fun clickable(isClickable: Boolean) {
getOrCreateNodeInfo().setClickable(isClickable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
mNodeInfo.getAccessibilityHeadingState() == NodeInfo.ACCESSIBILITY_HEADING_SET_TRUE);
}

if (mNodeInfo != null && mNodeInfo.getMinDurationBetweenContentChangesMillis() != null) {
node.setMinDurationBetweenContentChangesMillis(
mNodeInfo.getMinDurationBetweenContentChangesMillis());
}

if (mNodeInfo != null && mNodeInfo.getFocusOrder() != null && mountItem != null) {
final ComponentContext scopedContext = getComponentContext(mountItem.getRenderTreeNode());
final FocusOrderModel focusOrder = mNodeInfo.getFocusOrder();
Expand Down
18 changes: 18 additions & 0 deletions litho-core/src/main/java/com/facebook/litho/NodeInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class NodeInfo : Equivalence<NodeInfo> {
private var _sendAccessibilityEventUncheckedHandler:
EventHandler<SendAccessibilityEventUncheckedEvent>? =
null
private var _minDurationBetweenContentChangesMillis: Long? = null

var visibility: Visibility? = null
internal set(value) {
Expand Down Expand Up @@ -404,6 +405,13 @@ class NodeInfo : Equivalence<NodeInfo> {
_sendAccessibilityEventUncheckedHandler = sendAccessibilityEventUncheckedHandler
}

var minDurationBetweenContentChangesMillis: Long?
get() = _minDurationBetweenContentChangesMillis
set(duration) {
flags = flags or PFLAG_MIN_DURATION_BETWEEN_CHANGES_IS_SET
_minDurationBetweenContentChangesMillis = duration
}

fun needsAccessibilityDelegate(): Boolean =
_onInitializeAccessibilityEventHandler != null ||
_onInitializeAccessibilityNodeInfoHandler != null ||
Expand Down Expand Up @@ -671,6 +679,12 @@ class NodeInfo : Equivalence<NodeInfo> {
return false
}

if (!equals(
this.minDurationBetweenContentChangesMillis,
other.minDurationBetweenContentChangesMillis)) {
return false
}

return equals(this.viewTags, other.viewTags)
}

Expand Down Expand Up @@ -1012,5 +1026,9 @@ class NodeInfo : Equivalence<NodeInfo> {
private const val PFLAG_VISIBILITY_IS_SET = 1L shl 34

private const val PFLAG_FOCUS_ORDER_IS_SET = 1L shl 35

// When this flag is set, setMinDurationBetweenContentChangesMillis was explicitly set on this
// node.
private const val PFLAG_MIN_DURATION_BETWEEN_CHANGES_IS_SET = 1L shl 36
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ internal enum class AccessibilityField : StyleItemField {
ON_PERFORM_ACTION_FOR_VIRTUAL_VIEW,
ON_VIRTUAL_VIEW_KEYBOARD_FOCUS_CHANGED,
SCREEN_READER_FOCUSABLE,
MIN_DURATION_BETWEEN_CONTENT_CHANGES,
}

@PublishedApi
Expand Down Expand Up @@ -111,6 +112,8 @@ internal data class AccessibilityStyleItem(
eventHandler(value as (VirtualViewKeyboardFocusChangedEvent) -> Unit))
AccessibilityField.SCREEN_READER_FOCUSABLE ->
commonProps.screenReaderFocusable(value as Boolean)
AccessibilityField.MIN_DURATION_BETWEEN_CONTENT_CHANGES ->
commonProps.setMinDurationBetweenContentChangesMillis(value as Long)
}
}
}
Expand Down Expand Up @@ -312,6 +315,16 @@ inline fun Style.onInitializeAccessibilityNodeInfo(
inline fun Style.screenReaderFocusable(isFocusable: Boolean): Style =
this + AccessibilityStyleItem(AccessibilityField.SCREEN_READER_FOCUSABLE, isFocusable)

/**
* Sets the minimum time duration between two content change events, which is used in throttling
* content change events in accessibility services.
*
* See
* [androidx.core.view.accessibility.AccessibilityNodeInfoCompat.setMinDurationBetweenContentChangesMillis].
*/
inline fun Style.minDurationBetweenContentChangesMillis(duration: Long): Style =
this + AccessibilityStyleItem(AccessibilityField.MIN_DURATION_BETWEEN_CONTENT_CHANGES, duration)

/**
* Enum values for [importantForAccessibility].
*
Expand Down

0 comments on commit 18cf1e4

Please sign in to comment.