Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(iOS): Migrate RCTOnPageSelected to swift #939

Open
wants to merge 1 commit into
base: feature/switch-to-swift-pt1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions ios/Events/OnPageSelected.swift
Copy link
Member

Choose a reason for hiding this comment

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

nit: rename file so it matches class name

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Foundation
import React

@objc public class RCTOnPageSelected: NSObject, RCTEvent {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add @objcMembers

private var position: NSNumber
@objc public var viewTag: NSNumber
@objc public var coalescingKey: UInt16

@objc public var eventName: String {
return "onPageSelected"
}

@objc public init(reactTag: NSNumber, position: NSNumber, coalescingKey: UInt16) {
self.viewTag = reactTag
self.position = position
self.coalescingKey = coalescingKey
super.init()
}

@objc public func canCoalesce() -> Bool {
return false
}

Comment on lines +20 to +23
Copy link
Member

Choose a reason for hiding this comment

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

If canCoalesce is false you don't need to have coalescingKey and public func coalesce(with newEvent: RCTEvent) -> RCTEvent

Reference: https://github.com/facebook/react-native/blob/67bff8734f4b92fe399910eecad5b67511a749c1/packages/react-native/React/Base/RCTEventDispatcherProtocol.h#L51-L56

public func coalesce(with newEvent: RCTEvent) -> RCTEvent {
return newEvent
}

@objc public class func moduleDotMethod() -> String {
return "RCTEventEmitter.receiveEvent"
}

@objc public func arguments() -> [Any] {
return [
viewTag,
RCTNormalizeInputEventName(eventName) ?? eventName,
[
"position": position
]
]
}
}
14 changes: 0 additions & 14 deletions ios/RCTOnPageSelected.h

This file was deleted.

60 changes: 0 additions & 60 deletions ios/RCTOnPageSelected.m

This file was deleted.

1 change: 0 additions & 1 deletion ios/RNCPagerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#import "UIViewController+CreateExtension.h"
#import "RCTOnPageScrollStateChanged.h"
#import "RCTOnPageSelected.h"
#import <math.h>

#if __has_include("react_native_pager_view/react_native_pager_view-Swift.h")
Expand Down
1 change: 1 addition & 0 deletions ios/react-native-pager-view-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#import <React/RCTUIManager.h>
#import <React/UIView+React.h>
#import <React/RCTUtils.h>
#import <React/RCTAssert.h>
Copy link
Member

Choose a reason for hiding this comment

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

Is it needed?