-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
261 additions
and
42 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import <React/RCTUIManager.h> | ||
#import <React/RCTViewComponentView.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface PLKEmbeddedViewComponentView : RCTViewComponentView | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // RCT_NEW_ARCH_ENABLED |
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
|
||
#import "PLKEmbeddedViewComponentView.h" | ||
#import "PLKFabricHelpers.h" | ||
|
||
#import <React/RCTBridge+Private.h> | ||
#import <React/RCTConversions.h> | ||
#import <React/RCTFabricComponentsPlugins.h> | ||
|
||
#import <react/renderer/components/rnplaidlink/ComponentDescriptors.h> | ||
#import <react/renderer/components/rnplaidlink/EventEmitters.h> | ||
#import <react/renderer/components/rnplaidlink/Props.h> | ||
#import <react/renderer/components/rnplaidlink/RCTComponentViewHelpers.h> | ||
|
||
using namespace facebook::react; | ||
|
||
@implementation PLKEmbeddedViewComponentView { | ||
PLKEmbeddedView *_view; | ||
} | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame | ||
{ | ||
if (self = [super initWithFrame:frame]) { | ||
static const auto defaultProps = std::make_shared<const PLKEmbeddedViewProps>(); | ||
_props = defaultProps; | ||
[self prepareView]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)prepareView | ||
{ | ||
_view = [[PLKEmbeddedView alloc] init]; | ||
|
||
__weak __typeof__(self) weakSelf = self; | ||
|
||
[_view setOnEmbeddedEvent:^(NSDictionary* event) { | ||
__typeof__(self) strongSelf = weakSelf; | ||
|
||
if (strongSelf != nullptr && strongSelf->_eventEmitter != nullptr) { | ||
std::dynamic_pointer_cast<const facebook::react::PLKEmbeddedViewEventEmitter>(strongSelf->_eventEmitter)->onEmbeddedEvent({ | ||
.embeddedEventName = RCTStringFromNSString(event[@"embeddedEventName"]), | ||
.eventName = RCTStringFromNSString(event[@"eventName"]), | ||
.error = PLKConvertIdToFollyDynamic(event[@"error"]), | ||
.publicToken = RCTStringFromNSString(event[@"publicToken"]), | ||
.metadata = PLKConvertIdToFollyDynamic(event[@"metadata"]), | ||
}); | ||
} | ||
}]; | ||
self.contentView = _view; | ||
} | ||
|
||
#pragma mark - RCTComponentViewProtocol | ||
|
||
+ (ComponentDescriptorProvider)componentDescriptorProvider | ||
{ | ||
return concreteComponentDescriptorProvider<PLKEmbeddedViewComponentDescriptor>(); | ||
} | ||
|
||
|
||
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps | ||
{ | ||
const auto &newProps = static_cast<const PLKEmbeddedViewProps &>(*props); | ||
_view.token = RCTNSStringFromStringNilIfEmpty(newProps.token); | ||
_view.iOSPresentationStyle = RCTNSStringFromStringNilIfEmpty(newProps.token); | ||
|
||
[super updateProps:props oldProps:oldProps]; | ||
} | ||
|
||
- (void)prepareForRecycle | ||
{ | ||
[super prepareForRecycle]; | ||
[self prepareView]; | ||
} | ||
|
||
|
||
@end | ||
|
||
Class<RCTComponentViewProtocol> PLKEmbeddedViewCls(void) | ||
{ | ||
return PLKEmbeddedViewComponentView.class; | ||
} | ||
|
||
#endif // RCT_NEW_ARCH_ENABLED |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#import <React/RCTConversions.h> | ||
#import <folly/dynamic.h> | ||
#import <objc/runtime.h> | ||
|
||
#if __has_include(<rnplaidlink/react_native_plaid_link_sdk-Swift.h>) | ||
#import <rnplaidlink/react_native_plaid_link_sdk-Swift.h> | ||
#else | ||
#import <react_native_plaid_link_sdk-Swift.h> | ||
#endif | ||
|
||
// copied from RCTFollyConvert | ||
folly::dynamic PLKConvertIdToFollyDynamic(id json) | ||
{ | ||
if (json == nil || json == (id)kCFNull) { | ||
return nullptr; | ||
} else if ([json isKindOfClass:[NSNumber class]]) { | ||
const char *objCType = [json objCType]; | ||
switch (objCType[0]) { | ||
// This is a c++ bool or C99 _Bool. On some platforms, BOOL is a bool. | ||
case _C_BOOL: | ||
return (bool)[json boolValue]; | ||
case _C_CHR: | ||
// On some platforms, objc BOOL is a signed char, but it | ||
// might also be a small number. Use the same hack JSC uses | ||
// to distinguish them: | ||
// https://phabricator.intern.facebook.com/diffusion/FBS/browse/master/fbobjc/xplat/third-party/jsc/safari-600-1-4-17/JavaScriptCore/API/JSValue.mm;b8ee03916489f8b12143cd5c0bca546da5014fc9$901 | ||
if ([json isKindOfClass:[@YES class]]) { | ||
return (bool)[json boolValue]; | ||
} else { | ||
return [json longLongValue]; | ||
} | ||
case _C_UCHR: | ||
case _C_SHT: | ||
case _C_USHT: | ||
case _C_INT: | ||
case _C_UINT: | ||
case _C_LNG: | ||
case _C_ULNG: | ||
case _C_LNG_LNG: | ||
case _C_ULNG_LNG: | ||
return [json longLongValue]; | ||
|
||
case _C_FLT: | ||
case _C_DBL: | ||
return [json doubleValue]; | ||
|
||
// default: | ||
// fall through | ||
} | ||
} else if ([json isKindOfClass:[NSString class]]) { | ||
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding]; | ||
return std::string(reinterpret_cast<const char *>(data.bytes), data.length); | ||
} else if ([json isKindOfClass:[NSArray class]]) { | ||
folly::dynamic array = folly::dynamic::array; | ||
for (id element in json) { | ||
array.push_back(PLKConvertIdToFollyDynamic(element)); | ||
} | ||
return array; | ||
} else if ([json isKindOfClass:[NSDictionary class]]) { | ||
__block folly::dynamic object = folly::dynamic::object(); | ||
|
||
[json enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, __unused BOOL *stop) { | ||
object.insert(PLKConvertIdToFollyDynamic(key), PLKConvertIdToFollyDynamic(value)); | ||
}]; | ||
|
||
return object; | ||
} | ||
|
||
return nil; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// xcode tries to import this header in the auto-generated swift header | ||
// same as here: https://github.com/rnmapbox/maps/blob/b76c000a237b9757a616982d6c07f6ecfd7d60a9/ios/RNMBX/rnmapbox_maps.h |
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
Oops, something went wrong.