Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Swizzling crash(#533) #579

Closed
wants to merge 0 commits into from
Closed

Fixed Swizzling crash(#533) #579

wants to merge 0 commits into from

Conversation

Kevin-007
Copy link

@Kevin-007 Kevin-007 commented Sep 11, 2024

Summary

Fixed Swizzling crash(#533)
Add flag to prevent recurring calls
Remove delay swizzle to allow risk for skeletonLayoutSubviews() infinite loop calls

Requirements (place an x in each of the [ ])

@kikiwora
Copy link

It seems this change was reverted.
May we know why?

I am experiencing the same crash due to infinite recursion of skeletonLayoutSubviews() due to swizzling

@Kevin-007
Copy link
Author

Kevin-007 commented Dec 2, 2024

It seems this change was reverted. May we know why?

  • I have fork it and manage it as a internal library. Because the fix idea have changes and it works so far.
    The fixed solutions as below:
    Removed all unSwizzle method call:
        unSwizzleLayoutSubviews()
        unSwizzleTraitCollectionDidChange()

Updated all swizzle methods as below:

        DispatchQueue.once(token: "UIView.SkeletonView.swizzleLayoutSubviews") {
            swizzle(selector: #selector(UIView.layoutSubviews),
                    with: #selector(UIView.skeletonLayoutSubviews),
                    inClass: UIView.self,
                    usingClass: UIView.self)
            self.layoutSkeletonIfNeeded()
        }
        DispatchQueue.once(token: "UIView.SkeletonView.swizzleTraitCollectionDidChange") {
            swizzle(selector: #selector(UIView.traitCollectionDidChange(_:)),
                    with: #selector(UIView.skeletonTraitCollectionDidChange(_:)),
                    inClass: UIView.self,
                    usingClass: UIView.self)
        }

The root cause is swizzle by delay 0.01, and swizzle and unSwizzle frequently.
Hope it help for u, thank you.
@kikiwora

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants