Closed osdnk closed 4 years ago
It looks like you are using an older version of React Native. Please update to the latest release, v0.59 and verify if the issue still exists.
Updated version
cc @kelset @janicduplessis @kmagiera
Also, tried to make onLayout
as an event:
@interface RCTOnLayoutEvent : NSObject <RCTEvent>
- (instancetype)initWithReactTag:(NSNumber *)reactTag
content:(NSDictionary *)content;
@end
@implementation RCTOnLayoutEvent
{
NSDictionary *_content;
}
@synthesize viewTag = _viewTag;
@synthesize coalescingKey = _coalescingKey;
- (instancetype)initWithReactTag:(NSNumber *)reactTag
content:(NSDictionary *)content
{
static uint16_t coalescingKey = 0;
if ((self = [super init])) {
_coalescingKey = coalescingKey++;
_viewTag = reactTag;
_content = content;
}
return self;
}
RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (uint16_t)coalescingKey
{
return _coalescingKey;
}
- (NSString *)eventName
{
return @"onLayout";
}
- (BOOL)canCoalesce
{
return NO;
}
+ (NSString *)moduleDotMethod
{
return @"RCTEventEmitter.receiveEvent";
}
- (NSArray *)arguments
{
return @[self.viewTag, @"topLayout", _content];
}
- (id<RCTEvent>)coalesceWithEvent:(id<RCTEvent>)newEvent {
return newEvent;
}
@end
NSDictionary *content = @{
@"layout": @{
@"x": @(frame.origin.x),
@"y": @(frame.origin.y),
@"width": @(frame.size.width),
@"height": @(frame.size.height),
},
};
// shadowView.onLayout(content);
RCTOnLayoutEvent *layoutEvent = [[RCTOnLayoutEvent alloc] initWithReactTag:reactTag
content:content];
And it worked but events are being attached after mounting so this event is dispatching after filling a map with proper values in Native Animated Module.
Sorry I missed this, events defined with RCT{Direct|Bubbling}EventBlock
currently do not work with native animated. I made some PRs to fix it a while back but it ended up not getting merged until recently :(
Event improvement PR (prereq, merged): https://github.com/facebook/react-native/pull/15894 Actual fix (needs rebase): https://github.com/facebook/react-native/pull/15611
It should still work but just needs to be rebased on top of #15894
similar issue here(waste my whole day :( ): rn version : 0.59.9
In the meantime, has anyone been able to work around this issue? It seems there's no way to re-read the layout at all, and in my current implementation moving from an Animated.View
to a View
just breaks the layout entirely (because it depends on some animations).
Yeah - same here - this has taken up my whole day now. Thought it was going to be a 5 min bug when i first saw it.
This happened after upgrade from 0.57 - 0.59.10
Annoyingly any fix now will be added to > .6 versions and thats not an option for me right now, so need ti figure out a work around.
Any news about this issue ? I've got the bug on Android too (see snack here).
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
@yairopro Seems like a bug with react-native-reanimated, I changed your example to use Animated and it seems so work fine on Android.
https://snack.expo.io/@janic/onlayout-=-animated.event(..)-not-working
@osdnk Also works in Expo now so I assume my fix made it to a release, if you want to close this (Looks like I don't have the power to close issues anymore :()
(that's super weird! lmk if you want to close it)
@kelset yes please!
🐛 Bug Report
Behavior on Adnroid is expected one.
To Reproduce
Apply valued to
transform
and bind withAnimated.event
set toonLayout
prop inAnimated.View
.Expected Behavior
iOS should look like Android here. The value should hold a result of Animated.event's invocation.
Code Example
Environment