Skip to content

Use findContext for looking up app context#965

Merged
skydoves merged 1 commit intomainfrom
fix/context-regression
Apr 16, 2026
Merged

Use findContext for looking up app context#965
skydoves merged 1 commit intomainfrom
fix/context-regression

Conversation

@skydoves
Copy link
Copy Markdown
Owner

@skydoves skydoves commented Apr 16, 2026

Use findContext for looking up app context (#953)

Summary by CodeRabbit

Release Notes

  • Refactor
    • Updated internal Activity resolution mechanism across balloon components, improving how the library locates and interacts with parent activity context.

@skydoves skydoves self-assigned this Apr 16, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 573b8b63-482e-4717-aba3-fd289139ee65

📥 Commits

Reviewing files that changed from the base of the PR and between d8a308b and 9c2e1ad.

📒 Files selected for processing (6)
  • balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonModifier.kt
  • balloon/api/balloon.api
  • balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt
  • balloon/src/main/kotlin/com/skydoves/balloon/extensions/ContextExtension.kt
  • balloon/src/main/kotlin/com/skydoves/balloon/extensions/ViewExtension.kt
  • balloon/src/main/kotlin/com/skydoves/balloon/overlay/BalloonAnchorOverlayView.kt

Walkthrough

The changes refactor how the codebase retrieves Activity instances from Context. A new Context.findActivity(): Activity? extension function is added to safely traverse ContextWrapper chains and locate the underlying Activity, replacing direct Activity casts throughout the codebase.

Changes

Cohort / File(s) Summary
New Extension Utility
balloon/src/main/kotlin/com/skydoves/balloon/extensions/ContextExtension.kt
Added Context.findActivity(): Activity? extension function with @InternalBalloonApi and @JvmSynthetic annotations. Traverses ContextWrapper chain via baseContext to locate and return underlying Activity, returning null if not found.
API Surface Update
balloon/api/balloon.api
Exposed new ContextExtensionKt class with synthetic findActivity(Context): Activity? method to public API.
Compose Modifier Update
balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonModifier.kt
Updated Modifier.balloon() to opt into @OptIn(InternalBalloonApi::class). Changed anchor parent resolution from (context as? Activity)?.window?.decorView to context.findActivity()?.window?.decorView.
Activity Cast Replacements
balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt, balloon/src/main/kotlin/com/skydoves/balloon/extensions/ViewExtension.kt, balloon/src/main/kotlin/com/skydoves/balloon/overlay/BalloonAnchorOverlayView.kt
Replaced direct Activity casts with context.findActivity() extension calls. Updated null-safety checks and decorView access patterns to use the retrieved activity instance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A hop through contexts, we gently refine,
No casting about—just extensions divine!
ContextWrapper chains, we traverse with care,
Finding Activities nested with flair!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/context-regression

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@skydoves skydoves merged commit 5457011 into main Apr 16, 2026
4 of 5 checks passed
@skydoves skydoves deleted the fix/context-regression branch April 16, 2026 05:54
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.

1 participant