-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: some devices cannot immediately attach view, causing animation t…
…o fail fix: animation does not display on API less than 28
- Loading branch information
1 parent
de83d39
commit 354be69
Showing
7 changed files
with
180 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...revealswitch/src/main/java/com/yenaly/circularrevealswitch/CRActivityLifecycleCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.yenaly.circularrevealswitch | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.os.Bundle | ||
import android.util.Log | ||
import java.lang.ref.WeakReference | ||
|
||
/** | ||
* This is an implementation of the ActivityLifecycleCallbacks interface. | ||
* It is used to track the lifecycle of the current activity. | ||
* The current activity is stored as a weak reference to prevent memory leaks. | ||
* This class is particularly useful in scenarios where the DecorView changes after the activity is recreated, | ||
* as it allows us to get the new activity and obtain the new DecorView. | ||
* | ||
* In some devices, the DecorView changes after Activity is recreated, | ||
* which prevents the smooth reuse of DecorView. | ||
* To ensure compatibility, we use ActivityLifecycleCallback to get the new activity | ||
* and obtain the new DecorView. | ||
*/ | ||
object CRActivityLifecycleCallback : Application.ActivityLifecycleCallbacks { | ||
|
||
var currentActivity: WeakReference<Activity>? = null | ||
|
||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { | ||
activity.application.unregisterActivityLifecycleCallbacks(this) | ||
if (BuildConfig.ENABLE_LOGGING) { | ||
Log.d("CRActivityLifecycleCallback", "onActivityCreated: $activity") | ||
} | ||
currentActivity = activity.weak() | ||
} | ||
|
||
override fun onActivityStarted(activity: Activity) = Unit | ||
|
||
override fun onActivityResumed(activity: Activity) = Unit | ||
|
||
override fun onActivityPaused(activity: Activity) = Unit | ||
|
||
override fun onActivityStopped(activity: Activity) = Unit | ||
|
||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit | ||
|
||
override fun onActivityDestroyed(activity: Activity) { | ||
if (BuildConfig.ENABLE_LOGGING) { | ||
Log.d("CRActivityLifecycleCallback", "onActivityDestroyed: $activity") | ||
} | ||
currentActivity?.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.