-
Notifications
You must be signed in to change notification settings - Fork 24k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add RNTester example for native command Array param (#41897)
Summary: Pull Request resolved: #41897 Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D51875073 fbshipit-source-id: 403274b3063d7c49fe4642347d2f724d58a46c1f
- Loading branch information
1 parent
8e1c45a
commit 5d1eac0
Showing
12 changed files
with
238 additions
and
48 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
53 changes: 53 additions & 0 deletions
53
packages/rn-tester/NativeComponentExample/ios/RNTMyNativeViewCommon.mm
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,53 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "UIView+ColorOverlays.h" | ||
|
||
@implementation UIView (ColorOverlays) | ||
|
||
- (void)setBackgroundColorWithColorString:(NSString *)colorString | ||
{ | ||
UIColor *color = [UIView UIColorFromHexString:std::string([colorString UTF8String])]; | ||
self.backgroundColor = color; | ||
} | ||
|
||
- (void)addColorOverlays:(const NSArray *)overlayColors | ||
{ | ||
CGRect viewBounds = self.bounds; | ||
CGFloat width = viewBounds.size.width / [overlayColors count]; | ||
for (int i = 0; i < [overlayColors count]; i++) { | ||
id colorString = [overlayColors objectAtIndex:i]; | ||
CGRect rect = CGRectMake(viewBounds.origin.x + width * i, viewBounds.origin.y, width, viewBounds.size.height); | ||
UIView *overlayView = [[UIView alloc] initWithFrame:rect]; | ||
UIColor *color = [UIView UIColorFromHexString:std::string([colorString UTF8String])]; | ||
overlayView.backgroundColor = color; | ||
[self addSubview:overlayView]; | ||
} | ||
} | ||
|
||
- (void)removeOverlays | ||
{ | ||
NSArray *viewsToRemove = [self subviews]; | ||
for (UIView *subview in viewsToRemove) { | ||
[subview removeFromSuperview]; | ||
} | ||
} | ||
|
||
+ (UIColor *)UIColorFromHexString:(const std::string)hexString | ||
{ | ||
unsigned rgbValue = 0; | ||
NSString *colorString = [NSString stringWithCString:hexString.c_str() encoding:[NSString defaultCStringEncoding]]; | ||
NSScanner *scanner = [NSScanner scannerWithString:colorString]; | ||
[scanner setScanLocation:1]; // bypass '#' character | ||
[scanner scanHexInt:&rgbValue]; | ||
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 | ||
green:((rgbValue & 0xFF00) >> 8) / 255.0 | ||
blue:(rgbValue & 0xFF) / 255.0 | ||
alpha:1.0]; | ||
} | ||
|
||
@end |
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
23 changes: 23 additions & 0 deletions
23
packages/rn-tester/NativeComponentExample/ios/UIView+ColorOverlays.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <React/RCTComponent.h> | ||
#import <UIKit/UIKit.h> | ||
#import <string> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface UIView (ColorOverlays) | ||
|
||
- (void)setBackgroundColorWithColorString:(NSString *)colorString; | ||
- (void)addColorOverlays:(const NSArray *)overlayColors; | ||
- (void)removeOverlays; | ||
+ (UIColor *)UIColorFromHexString:(const std::string)hexString; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
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
Oops, something went wrong.