Skip to content

Commit

Permalink
fix(ios): fix some bugs
Browse files Browse the repository at this point in the history
1.layout subviews of HippyText
2. fix crash if HippyText.text is nil
3.delete onChange of HippyTextView
4.delete decleartion of HippyBubblingEventBlock.
  • Loading branch information
ozonelmy authored and xuqingkuang committed Apr 23, 2020
1 parent 80338e7 commit ce76475
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 54 deletions.
1 change: 0 additions & 1 deletion ios/sdk/base/HippyComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* properties. Unlike JS method callbacks, these can be called multiple times.
*/
typedef void (^HippyDirectEventBlock)(NSDictionary *body);
typedef void (^HippyBubblingEventBlock)(NSDictionary *body);

/**
* Logical node in a tree of application components. Both `ShadowView` and
Expand Down
26 changes: 2 additions & 24 deletions ios/sdk/base/HippyComponentData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ - (HippyPropBlock)propBlockForKey:(NSString *)name

// Build setter block
void (^setterBlock)(id target, id json) = nil;
if (type == NSSelectorFromString(@"HippyBubblingEventBlock:") ||
type == NSSelectorFromString(@"HippyDirectEventBlock:")) {
if (type == NSSelectorFromString(@"HippyDirectEventBlock:")) {

// Special case for event handlers
__weak HippyViewManager *weakManager = self.manager;
Expand Down Expand Up @@ -451,7 +450,6 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(HippyShado
- (NSDictionary<NSString *, id> *)viewConfig
{
NSMutableArray<NSString *> *directEvents = [NSMutableArray new];
NSMutableArray<NSString *> *bubblingEvents = [NSMutableArray new];
unsigned int count = 0;
NSMutableDictionary *propTypes = [NSMutableDictionary new];
Method *methods = class_copyMethodList(object_getClass(_managerClass), &count);
Expand All @@ -469,10 +467,7 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(HippyShado
"to '%@'", name, _name, propTypes[name], type);
}

if ([type isEqualToString:@"HippyBubblingEventBlock"]) {
[bubblingEvents addObject:HippyNormalizeInputEventName(name)];
propTypes[name] = @"BOOL";
} else if ([type isEqualToString:@"HippyDirectEventBlock"]) {
if ([type isEqualToString:@"HippyDirectEventBlock"]) {
[directEvents addObject:HippyNormalizeInputEventName(name)];
propTypes[name] = @"BOOL";
} else {
Expand All @@ -482,26 +477,9 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(HippyShado
}
}
free(methods);

if (HIPPY_DEBUG) {
for (NSString *event in directEvents) {
if ([bubblingEvents containsObject:event]) {
HippyLogError(@"Component '%@' registered '%@' as both a bubbling event "
"and a direct event", _name, event);
}
}
for (NSString *event in bubblingEvents) {
if ([directEvents containsObject:event]) {
HippyLogError(@"Component '%@' registered '%@' as both a bubbling event "
"and a direct event", _name, event);
}
}
}

return @{
@"propTypes" : propTypes,
@"directEvents" : directEvents,
@"bubblingEvents" : bubblingEvents,
};
}

Expand Down
3 changes: 2 additions & 1 deletion ios/sdk/component/text/HippyShadowText.mm
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
scaleMultiplier:_allowFontScaling ? _fontSizeMultiplier : 1.0];

CGFloat heightOfTallestSubview = 0.0;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.text];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.text?:@""];
for (HippyShadowView *child in [self hippySubviews]) {
if ([child isKindOfClass:[HippyShadowText class]]) {
HippyShadowText *shadowText = (HippyShadowText *)child;
Expand All @@ -375,6 +375,7 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
[child setTextComputed];
}else {
//MTTlayout
MTTNodeDoLayout(child.nodeRef, NAN, NAN);
float width = MTTNodeLayoutGetWidth(child.nodeRef);
float height = MTTNodeLayoutGetHeight(child.nodeRef);
if (isnan(width) || isnan(height)) {
Expand Down
2 changes: 0 additions & 2 deletions ios/sdk/component/textinput/HippyTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
@property (nonatomic, assign) NSInteger mostRecentEventCount;
@property (nonatomic, strong) NSNumber *maxLength;
@property (nonatomic, copy) HippyDirectEventBlock onKeyPress;

//@property (nonatomic, copy) HippyDirectEventBlock onChange;
@property (nonatomic, copy) HippyDirectEventBlock onContentSizeChange;
@property (nonatomic, copy) HippyDirectEventBlock onSelectionChange;
@property (nonatomic, copy) HippyDirectEventBlock onTextInput;
Expand Down
3 changes: 1 addition & 2 deletions ios/sdk/component/textinput/HippyTextViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ - (HippyShadowView *) shadowView {
HIPPY_REMAP_VIEW_PROPERTY(keyboardType, textView.keyboardType, UIKeyboardType)
HIPPY_REMAP_VIEW_PROPERTY(keyboardAppearance, textView.keyboardAppearance, UIKeyboardAppearance)
HIPPY_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
HIPPY_EXPORT_VIEW_PROPERTY(onChange, HippyBubblingEventBlock)
HIPPY_EXPORT_VIEW_PROPERTY(onContentSizeChange, HippyBubblingEventBlock)
HIPPY_EXPORT_VIEW_PROPERTY(onContentSizeChange, HippyDirectEventBlock)
HIPPY_EXPORT_VIEW_PROPERTY(onSelectionChange, HippyDirectEventBlock)
HIPPY_EXPORT_VIEW_PROPERTY(onTextInput, HippyDirectEventBlock)
HIPPY_EXPORT_VIEW_PROPERTY(onEndEditing, HippyDirectEventBlock)
Expand Down
24 changes: 0 additions & 24 deletions ios/sdk/module/uimanager/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,6 @@ - (void)setNeedsLayout:(NSNumber *)hippyTag
{
NSMutableDictionary<NSString *, NSDictionary *> *allJSConstants = [NSMutableDictionary new];
NSMutableDictionary<NSString *, NSDictionary *> *directEvents = [NSMutableDictionary new];
NSMutableDictionary<NSString *, NSDictionary *> *bubblingEvents = [NSMutableDictionary new];

[_componentDataByName enumerateKeysAndObjectsUsingBlock:
^(NSString *name, HippyComponentData *componentData, __unused BOOL *stop) {
Expand All @@ -1366,35 +1365,12 @@ - (void)setNeedsLayout:(NSNumber *)hippyTag
@"registrationName": [eventName stringByReplacingCharactersInRange:(NSRange){0, 3} withString:@"on"],
};
}
if (HIPPY_DEBUG && bubblingEvents[eventName]) {
HippyLogError(@"Component '%@' re-registered bubbling event '%@' as a "
"direct event", componentData.name, eventName);
}
}

// Add bubbling events
for (NSString *eventName in viewConfig[@"bubblingEvents"]) {
if (!bubblingEvents[eventName]) {
NSString *bubbleName = [eventName stringByReplacingCharactersInRange:(NSRange){0, 3} withString:@"on"];
bubblingEvents[eventName] = @{
@"phasedRegistrationNames": @{
@"bubbled": bubbleName,
@"captured": [bubbleName stringByAppendingString:@"Capture"],
}
};
}
if (HIPPY_DEBUG && directEvents[eventName]) {
HippyLogError(@"Component '%@' re-registered direct event '%@' as a "
"bubbling event", componentData.name, eventName);
}
}

allJSConstants[name] = constantsNamespace;
}];

_currentInterfaceOrientation = [HippySharedApplication() statusBarOrientation];
[allJSConstants addEntriesFromDictionary:@{
@"customBubblingEventTypes": bubblingEvents,
@"customDirectEventTypes": directEvents,
@"Dimensions": HippyExportedDimensions(NO)
}];
Expand Down

0 comments on commit ce76475

Please sign in to comment.