Skip to content

fix(ios): avoid double-initializing FLTPDFView#332

Open
muhammadbiilal wants to merge 2 commits into
endigo:masterfrom
muhammadbiilal:fix/ios-double-init-crash
Open

fix(ios): avoid double-initializing FLTPDFView#332
muhammadbiilal wants to merge 2 commits into
endigo:masterfrom
muhammadbiilal:fix/ios-double-init-crash

Conversation

@muhammadbiilal
Copy link
Copy Markdown

@muhammadbiilal muhammadbiilal commented Jan 23, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved iOS view initialization to reduce risk of crashes during UIView setup.
  • Documentation
    • Clarified recommended view creation pattern on iOS to ensure safe initialization during trait collection setup.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7e18b6d7-64b5-4ad9-a2c0-b2cf6f4b7f55

📥 Commits

Reviewing files that changed from the base of the PR and between 91400f2 and d44129e.

📒 Files selected for processing (1)
  • ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m

Walkthrough

The initializer for FLTPDFViewController now checks the result of [super init] and returns nil if initialization fails, and documents that FLTPDFView should be created with alloc/init (not new) to avoid UIKit trait-collection initialization issues.

Changes

Cohort / File(s) Summary
FLTPDFView initialization change
ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.m
Adds a nil-check for self after [super init]; replaces/clarifies FLTPDFView creation using alloc/init (comment explains avoiding new due to UIKit trait collection behavior).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through init with careful paws,
Alloc then init—respecting UIKit laws,
A tiny nil-check keeps the forest fine,
No trait-collection spikes on this rabbit's line. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(ios): avoid double-initializing FLTPDFView' directly describes the main change: fixing iOS initialization logic to prevent double-initialization of FLTPDFView.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@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;

@JaseElder
Copy link
Copy Markdown
Collaborator

Hi @muhammadbiilal, thanks for your PR.

This one looks to be fixed in 1.4.5-beta.2.

Can you double check that is the case?

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.

2 participants