Skip to content

Adds @objc from Slot feature and updates obj sample app#71

Open
Sonal-Kachare wants to merge 2 commits into
mainfrom
task/adds_objc_for_slot
Open

Adds @objc from Slot feature and updates obj sample app#71
Sonal-Kachare wants to merge 2 commits into
mainfrom
task/adds_objc_for_slot

Conversation

@Sonal-Kachare

@Sonal-Kachare Sonal-Kachare commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • New Features

    • Added JSON-based initialization methods for UI components (table/collection cells, view controllers) for direct JSON rendering.
    • Enhanced Objective-C interoperability with improved bridge APIs for native display functionality.
  • Improvements

    • Improved lifecycle management with proper listener registration during view appearance/disappearance.
    • Reorganized helper utilities for better maintainability.
  • Chores

    • Removed debug logging statements for cleaner runtime performance.

@Sonal-Kachare Sonal-Kachare requested a review from CTLalit June 23, 2026 10:35
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR expands the Objective-C interop surface of the core CleverTapNativeDisplay library by adding @objc annotations to protocols and methods, and adding JSON-data–based entry points to UIKit cells and view controllers. It introduces NDDisplayHelper as a consolidated ObjC bridge helper (replacing the deleted NDSampleHelpers/SampleHelpers.swift), and updates sample view controllers to use the new APIs with corrected lifecycle and threading patterns.

Changes

ObjC Interop + NDDisplayHelper Consolidation

Layer / File(s) Summary
Core library ObjC bridge surface annotations
ios/Sources/CleverTapNativeDisplay/Bridge/NativeDisplayBridgeListener.swift, ios/Sources/CleverTapNativeDisplay/Placement/NativeDisplaySlotManager.swift, ios/Sources/CleverTapNativeDisplay/Evaluator/VariableEvaluator.swift, ios/Sources/CleverTapNativeDisplay/Renderer/NativeDisplayRenderer.swift
onNativeDisplaysLoaded, NativeDisplaySlotObserver protocol callbacks, and NativeDisplaySlotManager registration/query methods gain @objc attributes; a new activeSlotIds() ObjC-friendly accessor is added. Debug log statements are removed from VariableEvaluator and NativeDisplayRenderer.
ObjC-compatible UIKit entry points via JSON data
ios/Sources/CleverTapNativeDisplay/UiKit/NativeDisplayCollectionViewCell.swift, ios/Sources/CleverTapNativeDisplay/UiKit/NativeDisplayTableViewCell.swift, ios/Sources/CleverTapNativeDisplay/UiKit/NativeDisplayViewController.swift
Each UIKit component gains an @objc public entry point that parses raw Data into ResolvedConfig and delegates to the existing Swift configure/init path, returning false or nil on parse failure.
NDDisplayHelper: factory methods, JSON loading, slot and font demo helpers
ios-objc-sample/NativeDisplaySampleObjc/NDDisplayHelper.swift
New NDDisplayHelper class consolidates ObjC-visible factory APIs: two createView overloads (one with arrangement strategy override), loadJSONData with bundle search and Resources/<dir> fallback, createFontDemoView wrapping a UIHostingController, and iOS 15+ slot view factories. NDSlotPlaceholderView (iOS 15+) implements NativeDisplaySlotObserver, managing install/removal of NativeDisplayUIView on window attachment and unit availability. NDFontDemoHostView injects optional font-family and parent-size environment values. SampleHelpers.swift (containing the superseded NDSampleHelpers and NDSlotPlaceholderView) is deleted.
Sample app migration to NDDisplayHelper and lifecycle/threading fixes
ios-objc-sample/NativeDisplaySampleObjc/BannerShowcaseViewController.m, ios-objc-sample/NativeDisplaySampleObjc/SlotDemoViewController.m, ios-objc-sample/NativeDisplaySampleObjc/BridgeIntegrationViewController.m, ios-objc-sample/NativeDisplaySampleObjc/CleverTapIntegrationViewController.m
BannerShowcaseViewController switches JSON loading from NDSampleHelpers to NDDisplayHelper. SlotDemoViewController replaces direct NDSlotPlaceholderView instantiation with NDDisplayHelper and updates CleverTap event names. BridgeIntegrationViewController moves unitIds KVC extraction inside the main-queue dispatch_async block. CleverTapIntegrationViewController moves NativeDisplayBridge listener registration from viewDidLoad to viewWillAppear/viewWillDisappear.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • CleverTap/clevertap-native-ui-kit#64: Both PRs modify NativeDisplaySlotManager.swift to add @objc annotations and ObjC-friendly APIs to the slot manager surface.
  • CleverTap/clevertap-native-ui-kit#65: Overlaps with changes to BannerShowcaseViewController.m and SlotDemoViewController.m, swapping which helper class is used for banner JSON loading and slot placeholder/display view creation.
  • CleverTap/clevertap-native-ui-kit#67: Directly related through BannerShowcaseViewController.m's predefined-banner loading path, switching from NDSampleHelpers to NDDisplayHelper, aligning with the broader helper class migration.

Suggested reviewers

  • CTLalit
  • piyush-kukadiya

Poem

🐇 Hop hop, the helpers now align,
NDDisplayHelper takes the lead in line.
@objc flags now pepper the code with care,
Placeholders appear when slot units are there.
Old SampleHelpers gone, a clean new trail—
The bunny's bridging Swift and ObjC without fail! 🎉

🚥 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 accurately describes the main changes: adding @objc attributes for Objective-C interoperability (particularly for the Slot feature) and updating the Objective-C sample app with new helper classes and refactored code.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/adds_objc_for_slot

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ios-objc-sample/NativeDisplaySampleObjc/NDDisplayHelper.swift`:
- Line 33: The condition checking parentWidth > 0 before subtracting 32 allows
negative inner widths when parentWidth is between 0 and 32, creating invalid
sizes. In the NDDisplayHelper.swift file, locate all three instances where
parentSize is being computed (at the lines handling parentWidth > 0 checks), and
modify the logic to ensure the resulting width value is never negative by either
changing the condition to check parentWidth >= 32, or by using a max operation
to clamp the computed width to a minimum of 0, ensuring valid sizing dimensions
are always passed to CGSize initialization.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44efad51-e829-49c5-b812-d5b01c7c5c16

📥 Commits

Reviewing files that changed from the base of the PR and between 2216c2b and bfe410e.

📒 Files selected for processing (13)
  • ios-objc-sample/NativeDisplaySampleObjc/BannerShowcaseViewController.m
  • ios-objc-sample/NativeDisplaySampleObjc/BridgeIntegrationViewController.m
  • ios-objc-sample/NativeDisplaySampleObjc/CleverTapIntegrationViewController.m
  • ios-objc-sample/NativeDisplaySampleObjc/NDDisplayHelper.swift
  • ios-objc-sample/NativeDisplaySampleObjc/SampleHelpers.swift
  • ios-objc-sample/NativeDisplaySampleObjc/SlotDemoViewController.m
  • ios/Sources/CleverTapNativeDisplay/Bridge/NativeDisplayBridgeListener.swift
  • ios/Sources/CleverTapNativeDisplay/Evaluator/VariableEvaluator.swift
  • ios/Sources/CleverTapNativeDisplay/Placement/NativeDisplaySlotManager.swift
  • ios/Sources/CleverTapNativeDisplay/Renderer/NativeDisplayRenderer.swift
  • ios/Sources/CleverTapNativeDisplay/UiKit/NativeDisplayCollectionViewCell.swift
  • ios/Sources/CleverTapNativeDisplay/UiKit/NativeDisplayTableViewCell.swift
  • ios/Sources/CleverTapNativeDisplay/UiKit/NativeDisplayViewController.swift
💤 Files with no reviewable changes (3)
  • ios/Sources/CleverTapNativeDisplay/Evaluator/VariableEvaluator.swift
  • ios/Sources/CleverTapNativeDisplay/Renderer/NativeDisplayRenderer.swift
  • ios-objc-sample/NativeDisplaySampleObjc/SampleHelpers.swift

) -> NativeDisplayUIView? {
do {
let config = try ResolvedConfig.from(jsonData: jsonData)
let parentSize: CGSize? = parentWidth > 0 ? CGSize(width: parentWidth - 32, height: 0) : nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clamp computed parent width before creating parentSize.

At Line 33, Line 102, and Line 147, parentWidth > 0 still allows negative inner widths when 0 < parentWidth < 32, which can produce invalid sizing.

💡 Proposed fix
-            let parentSize: CGSize? = parentWidth > 0 ? CGSize(width: parentWidth - 32, height: 0) : nil
+            let innerWidth = max(parentWidth - 32, 0)
+            let parentSize: CGSize? = innerWidth > 0 ? CGSize(width: innerWidth, height: 0) : nil
-            let parentSize: CGSize? = parentWidth > 0 ? CGSize(width: parentWidth - 32, height: 0) : nil
+            let innerWidth = max(parentWidth - 32, 0)
+            let parentSize: CGSize? = innerWidth > 0 ? CGSize(width: innerWidth, height: 0) : nil
-            let parentSize: CGSize? = parentWidth > 0 ? CGSize(width: parentWidth - 32, height: 0) : nil
+            let innerWidth = max(parentWidth - 32, 0)
+            let parentSize: CGSize? = innerWidth > 0 ? CGSize(width: innerWidth, height: 0) : nil

Also applies to: 102-102, 147-147

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ios-objc-sample/NativeDisplaySampleObjc/NDDisplayHelper.swift` at line 33,
The condition checking parentWidth > 0 before subtracting 32 allows negative
inner widths when parentWidth is between 0 and 32, creating invalid sizes. In
the NDDisplayHelper.swift file, locate all three instances where parentSize is
being computed (at the lines handling parentWidth > 0 checks), and modify the
logic to ensure the resulting width value is never negative by either changing
the condition to check parentWidth >= 32, or by using a max operation to clamp
the computed width to a minimum of 0, ensuring valid sizing dimensions are
always passed to CGSize initialization.

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