### Install ImpressionKit via CocoaPods Source: https://github.com/623637646/impressionkit/blob/master/README.md Add the ImpressionKit pod to your Podfile to integrate the library using CocoaPods. ```ruby pod 'ImpressionKit' ``` -------------------------------- ### Configuration Properties Source: https://github.com/623637646/impressionkit/blob/master/README.md Static and instance properties to configure detection behavior for all views or specific views/groups. ```APIDOC ## [Swift] Configuration Properties ### Description Static and instance properties to configure detection behavior for all views or specific views/groups. ### Properties - **detectionInterval** (TimeInterval) - Scan interval in seconds. Smaller means higher accuracy and CPU usage. - **durationThreshold** (TimeInterval) - Minimum duration (seconds) a view must be on screen to trigger impression. - **areaRatioThreshold** (CGFloat) - Minimum area ratio (0-1) of the view visible on screen. - **alphaThreshold** (CGFloat) - Minimum opacity (0-1) of the view. - **redetectOptions** (Redetect) - Options to retrigger impression events. ### Usage Examples ```swift // Apply to all views UIView.detectionInterval = 0.1 UIView.durationThreshold = 2 UIView.areaRatioThreshold = 0.4 UIView.alphaThreshold = 0.4 UIView.redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive] // Apply to a specific view let view = UIView() view.detectionInterval = 0.1 view.durationThreshold = 2 view.areaRatioThreshold = 0.4 view.alphaThreshold = 0.4 view.redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive] // Apply to a group let group = ImpressionGroup() group.detectionInterval = 0.1 group.durationThreshold = 2 group.areaRatioThreshold = 0.4 group.alphaThreshold = 0.4 group.redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive] ``` ### Redetect Options - **leftScreen** - Retrigger when view leaves screen and returns. - **viewControllerDidDisappear** - Retrigger when view controller disappears and reappears. - **didEnterBackground** - Retrigger when app enters background and returns. - **willResignActive** - Retrigger when app resigns active and becomes active. ``` -------------------------------- ### ImpressionGroup.init Source: https://github.com/623637646/impressionkit/blob/master/README.md Creates an ImpressionGroup for monitoring reusable views like those in UICollectionView, UITableView, or List. The callback provides the index path, view, and impression state. ```APIDOC ## [Swift] ImpressionGroup.init ### Description Creates an ImpressionGroup for monitoring reusable views like those in UICollectionView, UITableView, or List. The callback provides the index path, view, and impression state. ### Method Initializer ### Endpoint ImpressionGroup.init(handler:) ### Parameters #### Closure Parameters - **index** (IndexPath or Int) - The index of the view in the collection. - **view** (UIView or View) - The view being monitored. - **state** (ImpressionState) - The current impression state; check `state.isImpressed`. ### Request Example ```swift // UIKit var group = ImpressionGroup.init {(_, index: IndexPath, view, state) in if state.isImpressed { print("impressed index: \(index.row)") } } // SwiftUI var group = ImpressionGroup.init { (_, index: Int, _, state) in if state.isImpressed { print("impressed index: \(index)") } } ``` ### Response #### Success Response - **state.isImpressed** (Bool) - Indicates whether the view is currently impressed. #### Response Example ```swift // No direct return value; callback invoked with state. ``` ``` -------------------------------- ### UIView.detectImpression Source: https://github.com/623637646/impressionkit/blob/master/README.md Detects when a UIView becomes impressed (visible to users) based on configured thresholds. The callback provides the view and its impression state. ```APIDOC ## [Swift] UIView.detectImpression ### Description Detects when a UIView becomes impressed (visible to users) based on configured thresholds. The callback provides the view and its impression state. ### Method Swift method ### Endpoint UIView.detectImpression(handler:) ### Parameters #### Closure Parameters - **view** (UIView) - The view being monitored. - **state** (ImpressionState) - The current impression state; check `state.isImpressed`. ### Request Example ```swift UIView().detectImpression { (view, state) in if state.isImpressed { print("This view is impressed to users.") } } ``` ### Response #### Success Response - **state.isImpressed** (Bool) - Indicates whether the view is currently impressed. #### Response Example ```swift // No direct return value; callback invoked with state. ``` ``` -------------------------------- ### Set redetectOptions for all views, specific view, or group Source: https://github.com/623637646/impressionkit/blob/master/README.md Apply redetectOptions to control when impression events are retriggered. Setting on a specific view or group overrides the global default if non-nil. ```swift UIView.redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive] // apply to all views UIView().redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive] // apply to the specific view. `UIView.redetectOptions` will be used if it's nil. ImpressionGroup().redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive] // apply to the group. `UIView.redetectOptions` will be used if it's nil. ``` -------------------------------- ### Redetect options for retriggering impression events Source: https://github.com/623637646/impressionkit/blob/master/README.md Define Redetect options to retrigger impression events in specific situations: leftScreen, viewControllerDidDisappear, didEnterBackground, willResignActive. These are bitmask values. ```swift // When a view left from the screen, mark the view to retrigger the impression event when this view come back to the screen. // Left screen means the view is out of the screen but the UIViewController is still there. public static let leftScreen = Redetect(rawValue: 1 << 0) // When the UIViewController of the view disappear, mark the view to retrigger the impression event when the UIViewController appear again. public static let viewControllerDidDisappear = Redetect(rawValue: 1 << 1) // When the app enter background, mark the view to retrigger the impression event when the app enter foreground. public static let didEnterBackground = Redetect(rawValue: 1 << 2) // When the app will resign active, mark the view to retrigger the impression event when the app become active. public static let willResignActive = Redetect(rawValue: 1 << 3) ``` -------------------------------- ### Set areaRatioThreshold for all views, specific view, or group Source: https://github.com/623637646/impressionkit/blob/master/README.md Modify the threshold (from 0 to 1) for the area ratio of the view on the screen. If the percentage of the view's area on the screen exceeds this threshold, it may trigger an impression. ```swift UIView.areaRatioThreshold = 0.4 // apply to all views UIView().areaRatioThreshold = 0.4 // apply to the specific view. `UIView.areaRatioThreshold` will be used if it's nil. ImpressionGroup().areaRatioThreshold = 0.4 // apply to the group. `UIView.areaRatioThreshold` will be used if it's nil. ``` -------------------------------- ### SwiftUI View.detectImpression Source: https://github.com/623637646/impressionkit/blob/master/README.md SwiftUI modifier that detects when a view becomes impressed. The callback provides the impression state. ```APIDOC ## [Swift] View.detectImpression ### Description SwiftUI modifier that detects when a view becomes impressed. The callback provides the impression state. ### Method SwiftUI modifier ### Endpoint View.detectImpression(handler:) ### Parameters #### Closure Parameters - **state** (ImpressionState) - The current impression state; check `state.isImpressed`. ### Request Example ```swift Color.red.detectImpression { state in if state.isImpressed { print("This view is impressed to users.") } } ``` ### Response #### Success Response - **state.isImpressed** (Bool) - Indicates whether the view is currently impressed. #### Response Example ```swift // No direct return value; callback invoked with state. ``` ``` -------------------------------- ### Detect impression for UIView and SwiftUI view Source: https://github.com/623637646/impressionkit/blob/master/README.md Use detectImpression to receive impression state changes. The closure provides the view and state; check state.isImpressed to know when the view is impressed to users. ```swift // UIKit UIView().detectImpression { (view, state) in if state.isImpressed { print("This view is impressed to users.") } } ``` ```swift // SwiftUI Color.red.detectImpression { state in if state.isImpressed { print("This view is impressed to users.") } } ``` -------------------------------- ### Set alphaThreshold for all views, specific view, or group Source: https://github.com/623637646/impressionkit/blob/master/README.md Modify the threshold (from 0 to 1) for the view opacity. If the view's opacity exceeds this threshold, it may trigger an impression. ```swift UIView.alphaThreshold = 0.4 // apply to all views UIView().alphaThreshold = 0.4 // apply to the specific view. `UIView.alphaThreshold` will be used if it's nil. ImpressionGroup().alphaThreshold = 0.4 // apply to the group. `UIView.alphaThreshold` will be used if it's nil. ``` -------------------------------- ### ImpressionGroup.bind Source: https://github.com/623637646/impressionkit/blob/master/README.md Binds a reusable view to the ImpressionGroup with its index path. Typically called in cellForItemAt to track each cell. ```APIDOC ## [Swift] ImpressionGroup.bind ### Description Binds a reusable view to the ImpressionGroup with its index path. Typically called in cellForItemAt to track each cell. ### Method Instance method ### Endpoint ImpressionGroup.bind(view:index:) ### Parameters #### Parameters - **view** (UIView) - The view to bind (e.g., a cell). - **index** (IndexPath) - The index path of the view. ### Request Example ```swift func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell self.group.bind(view: cell, index: indexPath) return cell } ``` ### Response #### Success Response No return value. #### Response Example ```swift // No return value. ``` ``` -------------------------------- ### Set detectionInterval for all views, specific view, or group Source: https://github.com/623637646/impressionkit/blob/master/README.md Modify the detection (scan) interval in seconds. Smaller detectionInterval means higher accuracy and higher CPU consumption. Setting on a specific view or group overrides the global default if non-nil. ```swift UIView.detectionInterval = 0.1 // apply to all views UIView().detectionInterval = 0.1 // apply to the specific view. `UIView.detectionInterval` will be used if it's nil. ImpressionGroup().detectionInterval = 0.1 // apply to the group. `UIView.detectionInterval` will be used if it's nil. ``` -------------------------------- ### SwiftUI View.detectImpression(group:index:) Source: https://github.com/623637646/impressionkit/blob/master/README.md SwiftUI modifier to detect impression for a view within an ImpressionGroup, using an index. ```APIDOC ## [Swift] View.detectImpression(group:index:) ### Description SwiftUI modifier to detect impression for a view within an ImpressionGroup, using an index. ### Method SwiftUI modifier ### Endpoint View.detectImpression(group:index:) ### Parameters #### Parameters - **group** (ImpressionGroup) - The group to bind to. - **index** (Int) - The index of the view. ### Request Example ```swift List(0 ..< 100) { index in CellView(index: index) .frame(height: 100) .detectImpression(group: group, index: index) } ``` ### Response #### Success Response No return value. #### Response Example ```swift // No return value. ``` ``` -------------------------------- ### Set durationThreshold for all views, specific view, or group Source: https://github.com/623637646/impressionkit/blob/master/README.md Modify the threshold (seconds) for the duration of a view on the screen. If the view's duration on the screen exceeds this threshold, it may trigger an impression. ```swift UIView.durationThreshold = 2 // apply to all views UIView().durationThreshold = 2 // apply to the specific view. `UIView.durationThreshold` will be used if it's nil. ImpressionGroup().durationThreshold = 2 // apply to the group. `UIView.durationThreshold` will be used if it's nil. ``` -------------------------------- ### Use ImpressionGroup for reusable views (UIKit and SwiftUI) Source: https://github.com/623637646/impressionkit/blob/master/README.md ImpressionGroup is for UICollectionView, UITableView, List, or other reusable view cases. Bind each cell/view with its index in the group's closure to track impressions. ```swift // UIKit var group = ImpressionGroup.init {(_, index: IndexPath, view, state) in if state.isImpressed { print("impressed index: \(index.row)") } } ... func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell self.group.bind(view: cell, index: indexPath) return cell } ``` ```swift // SwiftUI var group = ImpressionGroup.init { (_, index: Int, _, state) in if state.isImpressed { print("impressed index: \(index)") } } var body: some View { List(0 ..< 100) { index in CellView(index: index) .frame(height: 100) .detectImpression(group: group, index: index) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.