From 70b4a7cf43c6771873b1e091029d332896d41a1a Mon Sep 17 00:00:00 2001 From: Donald Chen Date: Mon, 29 Nov 2021 16:50:14 -0800 Subject: [PATCH] delete deprecated child gesture region APIs (#33) --- .../PanelsChildGestureRegionObserver.kt | 21 +++---------------- .../com/discord/sampleapp/MainActivity.kt | 11 +++++----- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/overlapping_panels/src/main/java/com/discord/panels/PanelsChildGestureRegionObserver.kt b/overlapping_panels/src/main/java/com/discord/panels/PanelsChildGestureRegionObserver.kt index 9cbef44..1af3667 100644 --- a/overlapping_panels/src/main/java/com/discord/panels/PanelsChildGestureRegionObserver.kt +++ b/overlapping_panels/src/main/java/com/discord/panels/PanelsChildGestureRegionObserver.kt @@ -16,14 +16,13 @@ import java.lang.ref.WeakReference * Example usage: * 1) Use [PanelsChildGestureRegionObserver.Provider.get] to get an Activity-scoped instance of * [PanelsChildGestureRegionObserver] - * 2) Add the [PanelsChildGestureRegionObserver] instance as an android.view.OnLayoutChangeListener - * to each child view. + * 2) Register the child gesture region View with the [register]. * 3) In the parent of [OverlappingPanelsLayout], e.g. in a Fragment or Activity, implement * [GestureRegionsListener], and add the listener via [addGestureRegionsUpdateListener] * 4) Inside [GestureRegionsListener.onGestureRegionsUpdate], pass the child gesture regions to * [OverlappingPanelsLayout]. - * 5) Remember to remove views and listeners from [PanelsChildGestureRegionObserver] with [remove] - * and [removeGestureRegionsUpdateListener] in appropriate Android lifecycle methods. + * 5) Remember to unregister the child gesture region with [unregister] in appropriate Android + * lifecycle methods. */ class PanelsChildGestureRegionObserver : View.OnLayoutChangeListener { @@ -98,20 +97,6 @@ class PanelsChildGestureRegionObserver : View.OnLayoutChangeListener { viewIdToListenerMap[view.id] = listener } - /** - * Stop publishing gesture region updates based on layout changes to android.view.View - * corresponding to [viewId]. - */ - @Deprecated( - message = "Use unregister instead", - replaceWith = ReplaceWith("unregister(view)") - ) - @UiThread - fun remove(viewId: Int) { - viewIdToGestureRegionMap.remove(viewId) - publishGestureRegionsUpdate() - } - /** * Stop publishing gesture region updates based on layout and scroll changes to android.view.View */ diff --git a/sample_app/src/main/java/com/discord/sampleapp/MainActivity.kt b/sample_app/src/main/java/com/discord/sampleapp/MainActivity.kt index da81ec6..c0fecf2 100644 --- a/sample_app/src/main/java/com/discord/sampleapp/MainActivity.kt +++ b/sample_app/src/main/java/com/discord/sampleapp/MainActivity.kt @@ -60,13 +60,12 @@ class MainActivity : AppCompatActivity(), // To not handle panel gestures on selected child views, e.g. if the child view has its own // horizontal scroll handling, - // 1) Add PanelsChildGestureRegionObserver as an OnLayoutChangeListener on that child view + // 1) Register the child view as a gesture region. // 2) Make the host fragment / activity listen to child gesture region updates (e.g. in // onResume()). - // 3) Remember to remove the listener (e.g. in onPause() for an Activity), and remove the - // child view from PanelsChildGestureRegionObserver. + // 3) Remember to unregister the region (e.g. in onPause() for an Activity). // - // In this example, we're adding the OnLayoutChangeListener to a view in main_activity.xml. + // In this example, we're registering a view in main_activity.xml. // This will also work in other cases like child views in Fragments within MainActivity // because PanelsChildGestureRegionObserver.Provider.get() returns an Activity-scoped // singleton. @@ -95,7 +94,7 @@ class MainActivity : AppCompatActivity(), viewPager.apply { adapter = this@MainActivity.adapter - addOnLayoutChangeListener(PanelsChildGestureRegionObserver.Provider.get()) + PanelsChildGestureRegionObserver.Provider.get().register(this) } TabLayoutMediator(tabLayout, viewPager) { tab, position -> @@ -103,7 +102,7 @@ class MainActivity : AppCompatActivity(), }.attach() tabLayout.apply { - addOnLayoutChangeListener(PanelsChildGestureRegionObserver.Provider.get()) + PanelsChildGestureRegionObserver.Provider.get().register(tabLayout) } }