Created
February 22, 2018 08:13
-
-
Save AndreaVitale/6540e2d391ee3cb2d49dacad0a866573 to your computer and use it in GitHub Desktop.
Titanium Native Module - View Sizing
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
#import "TiUIView.h" | |
@interface ItAndreavitaleControllerTestView : TiUIView { | |
} | |
@property (nonatomic, retain) UIViewController* controller; | |
- (void)setContent:(UIView*)contentView; | |
@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
#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 |
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
#import "TiViewProxy.h" | |
#import "ItAndreavitaleControllerTestView.h" | |
@interface ItAndreavitaleControllerTestViewProxy : TiViewProxy { | |
} | |
@property (nonatomic, retain) TiViewProxy* contentViewProxy; | |
- (ItAndreavitaleControllerTestView *)child; | |
- (void)setContent:(id)args; | |
@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
#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