Skip to content

Instantly share code, notes, and snippets.

@AndreaVitale
Created February 22, 2018 08:13
Show Gist options
  • Save AndreaVitale/6540e2d391ee3cb2d49dacad0a866573 to your computer and use it in GitHub Desktop.
Save AndreaVitale/6540e2d391ee3cb2d49dacad0a866573 to your computer and use it in GitHub Desktop.
Titanium Native Module - View Sizing
#import "TiUIView.h"
@interface ItAndreavitaleControllerTestView : TiUIView {
}
@property (nonatomic, retain) UIViewController* controller;
- (void)setContent:(UIView*)contentView;
@end
#import "ItAndreavitaleControllerTestView.h"
@implementation ItAndreavitaleControllerTestView
- (void)initializeState {
if (_controller == nil) {
_controller = [[UIViewController alloc] init];
_controller.view = [[UIView alloc] initWithFrame:self.frame];
_controller.view.backgroundColor = [UIColor redColor];
[self addSubview:_controller.view];
}
[super initializeState];
}
- (void)setContent:(UIView*)contentView {
[_controller.view addSubview:contentView];
}
- (void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds {
[TiUtils setView:_controller.view positionRect:bounds];
for (UIView* child in _controller.view.subviews) {
[TiUtils setView:child positionRect:bounds];
}
[super frameSizeChanged:frame bounds:bounds];
}
@end
#import "TiViewProxy.h"
#import "ItAndreavitaleControllerTestView.h"
@interface ItAndreavitaleControllerTestViewProxy : TiViewProxy {
}
@property (nonatomic, retain) TiViewProxy* contentViewProxy;
- (ItAndreavitaleControllerTestView *)child;
- (void)setContent:(id)args;
@end
#import "ItAndreavitaleControllerTestViewProxy.h"
#import "TiUtils.h"
@implementation ItAndreavitaleControllerTestViewProxy
- (ItAndreavitaleControllerTestView *)child {
return (ItAndreavitaleControllerTestView*)self.view;
}
- (void)setContent:(id)args {
ENSURE_UI_THREAD(setContent, args);
ENSURE_TYPE(args, TiViewProxy);
if (_contentViewProxy != nil) {
[_contentViewProxy.view removeFromSuperview];
[self forgetProxy:_contentViewProxy];
}
_contentViewProxy = (TiViewProxy* )args;
[self rememberProxy:_contentViewProxy];
// Adding as a child
[[self child] setContent:_contentViewProxy.view];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment