Skip to content

Conversation

@muhammadbiilal
Copy link

@muhammadbiilal muhammadbiilal commented Jan 23, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved initialization reliability on iOS to prevent potential crashes during UIView setup.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

The change modifies the iOS Flutter PDF view initialization to replace the new method with an explicit alloc/init sequence, adds a nil-check for the resulting object, and includes a comment explaining the connection to UIKit trait collection initialization behavior.

Changes

Cohort / File(s) Summary
FLTPDFView initialization refactoring
ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m
Replaces [[FLTPDFView new] with [[FLTPDFView alloc] initWithFrame: pattern; adds nil-check for self post-initialization; includes explanatory comment about UIKit trait collection setup

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop and a bound through initialization code,
Alloc and init dance down the UIKit road,
No more the shortcut, now safe and refined,
Trait collections blessed, no crashes to find! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the iOS implementation by avoiding double-initialization of FLTPDFView, which is the core issue addressed in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m (1)

114-117: Critical: Missing [super initWithFrame:frame] call in FLTPDFView.

The initWithFrame:arguments:controller: method sets instance variables and returns self without ever calling the superclass initializer. Since FLTPDFView is a UIView subclass (it calls addSubview: on line 244), you must call [super initWithFrame:frame] to properly initialize the view hierarchy.

Without this, the UIView is left in an undefined state, which could cause crashes or undefined behavior—especially on newer iOS versions with trait collection initialization.

🐛 Proposed fix
 - (instancetype)initWithFrame:(CGRect)frame
                     arguments:(id _Nullable)args
                     controller:(nonnull FLTPDFViewController *)controller {
+    self = [super initWithFrame:frame];
+    if (!self) return nil;
+
     _controller = controller;

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