'Update app properties in runtime' UIExplorer demo

Reviewed By: javache

Differential Revision: D2615815

fb-gh-sync-id: 557ce1b2bc76360fe19a0893e0f317c09b685e23
This commit is contained in:
Pawel Sienkowski
2015-11-12 11:39:05 -08:00
committed by facebook-github-bot-2
parent eae91cc680
commit f1712b0cc3
9 changed files with 270 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#import <UIKit/UIKit.h>
#import "RCTView.h"
@interface UpdatePropertiesExampleView : RCTView
@end

View File

@@ -0,0 +1,94 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#import "AppDelegate.h"
#import "UpdatePropertiesExampleView.h"
#import "RCTJavaScriptLoader.h"
#import "RCTBridge.h"
#import "RCTRootView.h"
#import "RCTViewManager.h"
@interface UpdatePropertiesExampleViewManager : RCTViewManager
@end
@implementation UpdatePropertiesExampleViewManager
RCT_EXPORT_MODULE();
- (UIView *)view
{
return [UpdatePropertiesExampleView new];
}
@end
@implementation UpdatePropertiesExampleView
{
RCTRootView *_rootView;
UIButton *_button;
BOOL _beige;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_beige = YES;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_rootView = [[RCTRootView alloc] initWithBridge:appDelegate.bridge
moduleName:@"SetPropertiesExampleApp"
initialProperties:@{@"color":@"beige"}];
_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_button setTitle:@"Native Button" forState:UIControlStateNormal];
[_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_button setBackgroundColor:[UIColor grayColor]];
[_button addTarget:self
action:@selector(changeColor)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_button];
[self addSubview:_rootView];
}
return self;
}
- (void)layoutSubviews
{
float spaceHeight = 20;
float buttonHeight = 40;
float rootViewWidth = self.bounds.size.width;
float rootViewHeight = self.bounds.size.height - spaceHeight - buttonHeight;
[_rootView setFrame:CGRectMake(0, 0, rootViewWidth, rootViewHeight)];
[_button setFrame:CGRectMake(0, rootViewHeight + spaceHeight, rootViewWidth, buttonHeight)];
}
- (void)changeColor
{
_beige = !_beige;
[_rootView setAppProperties:@{@"color":_beige ? @"beige" : @"purple"}];
}
- (NSArray<UIView<RCTComponent> *> *)reactSubviews
{
return @[];
}
@end