Skip to content

Commit

Permalink
feat(ios): add Ti.UI.TextField/Area focused property
Browse files Browse the repository at this point in the history
Fixes TIMOB-27711
  • Loading branch information
sgtcoolguy committed Jun 22, 2020
1 parent 19ab4dc commit 5e822f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions iphone/Classes/TiUITextWidget.h
Expand Up @@ -30,6 +30,7 @@
@private
}

@property (readonly, getter=isFocused) BOOL focused;
- (void)textWidget:(UIView<UITextInputTraits> *)tw didFocusWithText:(NSString *)value;
- (void)textWidget:(UIView<UITextInputTraits> *)tw didBlurWithText:(NSString *)value;
- (void)setValue_:(id)text;
Expand Down
4 changes: 4 additions & 0 deletions iphone/Classes/TiUITextWidget.m
Expand Up @@ -17,6 +17,8 @@

@implementation TiUITextWidget

@synthesize focused;

#ifdef TI_USE_AUTOLAYOUT
- (void)initializeTiLayoutView
{
Expand Down Expand Up @@ -193,6 +195,7 @@ - (void)setAutocapitalization_:(id)value
- (void)textWidget:(UIView<UITextInputTraits> *)tw didFocusWithText:(NSString *)value
{
TiUITextWidgetProxy *ourProxy = (TiUITextWidgetProxy *)[self proxy];
focused = YES;
[[ourProxy keyboardAccessoryView] setBounds:CGRectMake(0, 0, 0, [ourProxy keyboardAccessoryHeight])];

[[TiApp controller] didKeyboardFocusOnProxy:(TiViewProxy<TiKeyboardFocusableView> *)ourProxy];
Expand All @@ -209,6 +212,7 @@ - (void)textWidget:(UIView<UITextInputTraits> *)tw didFocusWithText:(NSString *)
- (void)textWidget:(UIView<UITextInputTraits> *)tw didBlurWithText:(NSString *)value
{
TiUITextWidgetProxy *ourProxy = (TiUITextWidgetProxy *)[self proxy];
focused = NO;

[[TiApp controller] didKeyboardBlurOnProxy:(TiViewProxy<TiKeyboardFocusableView> *)ourProxy];

Expand Down
8 changes: 7 additions & 1 deletion iphone/Classes/TiUITextWidgetProxy.m
Expand Up @@ -89,7 +89,13 @@ - (void)focus:(id)args
// This is exposed to JS as "focused" property
- (BOOL)isFocused
{
return [self focused:nil];
if ([self viewAttached]) {
// we explicitly defer to underlying class
// because the focus event gets fired *before* isFirstResponder call would return true (impl in focused method below)
// So we toggle a boolean flag in the impl's focus/blur methods
return [(TiUITextWidget *)[self view] isFocused];
}
return NO;
}

- (BOOL)focused:(id)unused
Expand Down

0 comments on commit 5e822f5

Please sign in to comment.