-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support onFallbackAction prop on view and cleanup ios/android
- Loading branch information
1 parent
a08a775
commit aead9ed
Showing
10 changed files
with
157 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,63 @@ | ||
import CommandBarIOS | ||
|
||
@objc(HelpHubViewManager) | ||
class HelpHubViewManager: RCTViewManager { | ||
@objc var options: NSDictionary? | ||
@objc var onFallbackAction: RCTDirectEventBlock? | ||
|
||
override func view() -> UIView! { | ||
let options = CommandBarOptions(dictionary: self.options as! [String : Any]) | ||
let helpHubWebView = HelpHubWebView(frame: CGRect.zero, options: options) | ||
helpHubWebView.delegate = self | ||
return helpHubWebView | ||
@objc(RNEventEmitter) | ||
class RNEventEmitter : RCTEventEmitter { | ||
|
||
public static var emitter: RCTEventEmitter! | ||
|
||
override init() { | ||
super.init() | ||
RNEventEmitter.emitter = self | ||
} | ||
|
||
override func supportedEvents() -> [String] { | ||
["onFallbackAction"] | ||
} | ||
|
||
public override static func requiresMainQueueSetup() -> Bool { | ||
return true | ||
} | ||
} | ||
|
||
override static func requiresMainQueueSetup() -> Bool { | ||
return true | ||
class RNHelpHubView : UIView { | ||
@objc var options: NSDictionary? { | ||
didSet { | ||
self.helpHubWebView.options = CommandBarOptions(options as! [String : Any]) | ||
} | ||
} | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
self.addSubview(helpHubWebView) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
} | ||
|
||
lazy var helpHubWebView: HelpHubWebView = { | ||
let webview = HelpHubWebView(frame: CGRect.zero) | ||
webview.delegate = self | ||
webview.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
return webview | ||
}() | ||
} | ||
|
||
extension HelpHubViewManager: HelpHubWebViewDelegate { | ||
extension RNHelpHubView: HelpHubWebViewDelegate { | ||
func didReceiveFallbackAction(_ action: [String : Any]) { | ||
self.onFallbackAction?(action) | ||
RNEventEmitter.emitter.sendEvent(withName: "onFallbackAction", body: action) | ||
} | ||
} | ||
|
||
|
||
@objc(HelpHubViewManager) | ||
class HelpHubViewManager: RCTViewManager { | ||
override func view() -> UIView! { | ||
return RNHelpHubView() | ||
} | ||
|
||
override static func requiresMainQueueSetup() -> Bool { | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,46 @@ | ||
import { NativeModules, Platform } from 'react-native'; | ||
import type { HelpHubView } from './HelpHubView'; | ||
|
||
export type CommandBarOptions = { | ||
orgId: string; | ||
userId?: string; | ||
spinnerColor?: string; | ||
launchCode?: string; | ||
}; | ||
|
||
// Define type for the LINKING_ERROR constant | ||
const LINKING_ERROR: string = | ||
`The package 'react-native-commandbar' doesn't seem to be linked. Make sure: \n\n` + | ||
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + | ||
'- You rebuilt the app after installing the package\n' + | ||
'- You are not using Expo Go\n'; | ||
|
||
export type RNCommandBar = { | ||
openHelpHub( | ||
options: CommandBarOptions, | ||
onFallbackAction?: (action: any) => void | ||
): void; | ||
HelpHubView: typeof HelpHubView; | ||
}; | ||
|
||
export const RNCommandBar = NativeModules.RNCommandBar | ||
? NativeModules.RNCommandBar | ||
: new Proxy( | ||
{}, | ||
{ | ||
get() { | ||
throw new Error(LINKING_ERROR); | ||
}, | ||
} | ||
); | ||
|
||
export const RNEventEmitter = NativeModules.RNEventEmitter | ||
? NativeModules.RNEventEmitter | ||
: new Proxy( | ||
{}, | ||
{ | ||
get() { | ||
throw new Error(LINKING_ERROR); | ||
}, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters