From bd31a1e86c76bc809d30ee50c62fb1f68f2a17a5 Mon Sep 17 00:00:00 2001 From: Peng Jiang Date: Mon, 4 Dec 2023 13:17:55 -0800 Subject: [PATCH] Rename method to make it clear Summary: rename few functions as they are just callbacks to react on events. Reviewed By: fabiocarballo Differential Revision: D51756466 fbshipit-source-id: 46b3c4f139b6d844c2c0d2b872ee4dcd651bc9af --- CHANGELOG.md | 1 + .../accessibility/AccessibilityStyles.kt | 25 ++++++++++--------- .../accessibility/AccessibilityStylesTest.kt | 16 ++++++------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 968b6b3f3a0..f52adec45ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Version 0.49.0-SNAPSHOT * [BREAKING] Removed `Component.canResolve()` and `Component.resolve(ResolveContext, ComponentContext)` methods. All classes extending Component must now implement the new `Component.resolve(ResolveContext, ScopedComponentInfo, int, int, ComponentsLogger)` method which is always used in the resolution flow. +* [BREAKING] Rename `Style.performAccessibilityAction`, `Style.sendAccessibilityEvent` and `Style.sendAccessibilityEventUnchecked` methods. For more details, see the [full diff](https://github.com/facebook/litho/compare/v0.48.0...master). diff --git a/litho-core-kotlin/src/main/kotlin/com/facebook/litho/accessibility/AccessibilityStyles.kt b/litho-core-kotlin/src/main/kotlin/com/facebook/litho/accessibility/AccessibilityStyles.kt index ceeefc6f266..017a70f3054 100644 --- a/litho-core-kotlin/src/main/kotlin/com/facebook/litho/accessibility/AccessibilityStyles.kt +++ b/litho-core-kotlin/src/main/kotlin/com/facebook/litho/accessibility/AccessibilityStyles.kt @@ -202,29 +202,29 @@ inline fun Style.onRequestSendAccessibilityEvent( onRequestSendAccessibilityEventHandler) /** - * Performs the specified accessibility action on the view. + * Called when performs the specified accessibility action on the view. * * See [android.view.View.AccessibilityDelegateCompat#performAccessibilityAction]. */ -inline fun Style.performAccessibilityAction( - noinline performAccessibilityActionHandler: (PerformAccessibilityActionEvent) -> Unit +inline fun Style.onPerformAccessibilityAction( + noinline onPerformAccessibilityActionHandler: (PerformAccessibilityActionEvent) -> Unit ): Style = this + AccessibilityStyleItem( - AccessibilityField.PERFORM_ACCESSIBILITY_ACTION, performAccessibilityActionHandler) + AccessibilityField.PERFORM_ACCESSIBILITY_ACTION, onPerformAccessibilityActionHandler) /** - * Sends an accessibility event of the given type. If accessibility is not enabled this method has - * no effect. + * Called when Sends an accessibility event of the given type. If accessibility is not enabled this + * method has no effect. * * See [android.view.View.AccessibilityDelegateCompat#sendAccessibilityEvent]. */ -inline fun Style.sendAccessibilityEvent( - noinline sendAccessibilityEventHandler: (SendAccessibilityEventEvent) -> Unit +inline fun Style.onSendAccessibilityEvent( + noinline onSendAccessibilityEventHandler: (SendAccessibilityEventEvent) -> Unit ): Style = this + AccessibilityStyleItem( - AccessibilityField.SEND_ACCESSIBILITY_EVENT, sendAccessibilityEventHandler) + AccessibilityField.SEND_ACCESSIBILITY_EVENT, onSendAccessibilityEventHandler) /** * Sends an accessibility event. This method behaves exactly as sendAccessibilityEvent() but takes @@ -233,13 +233,14 @@ inline fun Style.sendAccessibilityEvent( * * See [android.view.View.AccessibilityDelegateCompat#sendAccessibilityEventUnchecked]. */ -inline fun Style.sendAccessibilityEventUnchecked( - noinline sendAccessibilityEventUncheckedHandler: (SendAccessibilityEventUncheckedEvent) -> Unit +inline fun Style.onSendAccessibilityEventUnchecked( + noinline onSendAccessibilityEventUncheckedHandler: + (SendAccessibilityEventUncheckedEvent) -> Unit ): Style = this + AccessibilityStyleItem( AccessibilityField.SEND_ACCESSIBILITY_EVENT_UNCHECKED, - sendAccessibilityEventUncheckedHandler) + onSendAccessibilityEventUncheckedHandler) /** * Initializes an [AccessibilityNodeInfoCompat] with information about the host view. diff --git a/litho-core-kotlin/src/test/kotlin/com/facebook/litho/accessibility/AccessibilityStylesTest.kt b/litho-core-kotlin/src/test/kotlin/com/facebook/litho/accessibility/AccessibilityStylesTest.kt index cc4489e1617..b342254cf32 100644 --- a/litho-core-kotlin/src/test/kotlin/com/facebook/litho/accessibility/AccessibilityStylesTest.kt +++ b/litho-core-kotlin/src/test/kotlin/com/facebook/litho/accessibility/AccessibilityStylesTest.kt @@ -252,12 +252,12 @@ class AccessibilityStylesTest { /** See comment on [onInitializeAccessibilityNodeInfo_whenNotSet_isNotSetOnView] above. */ @Test - fun performAccessibilityAction_whenSet_isSetOnView() { + fun onPerformAccessibilityAction_whenSet_isSetOnView() { val eventHandler: EventHandler = mock() class TestComponentWithHandler : KComponent() { override fun ComponentScope.render(): Component? { - return Row(style = Style.performAccessibilityAction { eventHandler }) + return Row(style = Style.onPerformAccessibilityAction { eventHandler }) } } val testLithoView = lithoViewRule.render { TestComponentWithHandler() } @@ -268,7 +268,7 @@ class AccessibilityStylesTest { /** See comment on [onInitializeAccessibilityNodeInfo_whenNotSet_isNotSetOnView] above. */ @Test - fun sendAccessibilityEvent_whenNotSet_isNotSetOnView() { + fun onSendAccessibilityEvent_whenNotSet_isNotSetOnView() { class TestComponent : KComponent() { override fun ComponentScope.render(): Component? { return Row(style = Style.width(200.px)) @@ -282,12 +282,12 @@ class AccessibilityStylesTest { /** See comment on [onInitializeAccessibilityNodeInfo_whenNotSet_isNotSetOnView] above. */ @Test - fun sendAccessibilityEvent_whenSet_isSetOnView() { + fun onSendAccessibilityEvent_whenSet_isSetOnView() { val eventHandler: EventHandler = mock() class TestComponentWithHandler : KComponent() { override fun ComponentScope.render(): Component? { - return Row(style = Style.sendAccessibilityEvent { eventHandler }) + return Row(style = Style.onSendAccessibilityEvent { eventHandler }) } } val testLithoView = lithoViewRule.render { TestComponentWithHandler() } @@ -298,7 +298,7 @@ class AccessibilityStylesTest { /** See comment on [onInitializeAccessibilityNodeInfo_whenNotSet_isNotSetOnView] above. */ @Test - fun sendAccessibilityEventUnchecked_whenNotSet_isNotSetOnView() { + fun onSendAccessibilityEventUnchecked_whenNotSet_isNotSetOnView() { class TestComponent : KComponent() { override fun ComponentScope.render(): Component? { return Row(style = Style.width(200.px)) @@ -312,12 +312,12 @@ class AccessibilityStylesTest { /** See comment on [onInitializeAccessibilityNodeInfo_whenNotSet_isNotSetOnView] above. */ @Test - fun sendAccessibilityEventUnchecked_whenSet_isSetOnView() { + fun onSendAccessibilityEventUnchecked_whenSet_isSetOnView() { val eventHandler: EventHandler = mock() class TestComponentWithHandler : KComponent() { override fun ComponentScope.render(): Component? { - return Row(style = Style.sendAccessibilityEventUnchecked { eventHandler }) + return Row(style = Style.onSendAccessibilityEventUnchecked { eventHandler }) } } val testLithoView = lithoViewRule.render { TestComponentWithHandler() }