Skip to content

Commit a240f08

Browse files
fix: SkeletonLayout: Use handler in showSkeleton and hideSkeleton
1 parent 973f3b2 commit a240f08

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonLayout.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package dev.enginecrafter77.skeletonlayoutng;
1818

1919
import android.content.Context;
20+
import android.os.Handler;
21+
import android.os.Looper;
2022
import android.util.AttributeSet;
2123
import android.view.View;
2224
import android.widget.FrameLayout;
@@ -40,6 +42,7 @@
4042
*/
4143
public class SkeletonLayout extends FrameLayout implements Skeleton {
4244
private final SkeletonDrawable skeletonDrawable;
45+
private final Handler handler;
4346

4447
public SkeletonLayout(@NonNull Context context)
4548
{
@@ -49,6 +52,7 @@ public SkeletonLayout(@NonNull Context context)
4952
public SkeletonLayout(@NonNull Context context, @Nullable AttributeSet attrs)
5053
{
5154
super(context, attrs);
55+
this.handler = new Handler(Looper.getMainLooper());
5256
this.skeletonDrawable = new SkeletonDrawable();
5357
this.getOverlay().add(this.skeletonDrawable);
5458

@@ -71,14 +75,18 @@ public boolean isActive()
7175
@Override
7276
public void showSkeleton()
7377
{
74-
ViewGroupChildIterator.asIterable(this).forEach((View view) -> view.setVisibility(View.INVISIBLE));
75-
this.skeletonDrawable.showSkeleton();
78+
this.handler.post(() -> {
79+
ViewGroupChildIterator.asIterable(this).forEach((View view) -> view.setVisibility(View.INVISIBLE));
80+
this.skeletonDrawable.showSkeleton();
81+
});
7682
}
7783

7884
@Override
7985
public void hideSkeleton()
8086
{
81-
ViewGroupChildIterator.asIterable(this).forEach((View view) -> view.setVisibility(View.VISIBLE));
82-
this.skeletonDrawable.hideSkeleton();
87+
this.handler.post(() -> {
88+
ViewGroupChildIterator.asIterable(this).forEach((View view) -> view.setVisibility(View.VISIBLE));
89+
this.skeletonDrawable.hideSkeleton();
90+
});
8391
}
8492
}

0 commit comments

Comments
 (0)