11
11
import android .view .View ;
12
12
import android .view .ViewGroup ;
13
13
14
+ import com .facebook .react .bridge .Arguments ;
14
15
import com .facebook .react .bridge .Callback ;
16
+ import com .facebook .react .bridge .ReactContext ;
17
+ import com .facebook .react .bridge .WritableMap ;
18
+ import com .facebook .react .uimanager .PixelUtil ;
15
19
import com .facebook .react .uimanager .ThemedReactContext ;
16
- import com .facebook .react .uimanager .UIBlock ;
17
- import com .facebook .react .uimanager .UIManagerModule ;
18
- import com .facebook .react .uimanager .NativeViewHierarchyManager ;
20
+ import com .facebook .react .uimanager .events .RCTEventEmitter ;
19
21
20
22
public class RNSharedElementTransition extends ViewGroup {
21
23
static private String LOG_TAG = "RNSharedElementTransition" ;
@@ -295,6 +297,16 @@ private void updateLayout() {
295
297
}
296
298
}
297
299
}
300
+
301
+ // Fire events
302
+ if ((startStyle != null ) && !startItem .getHasCalledOnMeasure ()) {
303
+ startItem .setHasCalledOnMeasure (true );
304
+ fireMeasureEvent ("startNode" , startItem , startClippedLayout );
305
+ }
306
+ if ((endStyle != null ) && !endItem .getHasCalledOnMeasure ()) {
307
+ endItem .setHasCalledOnMeasure (true );
308
+ fireMeasureEvent ("endNode" , endItem , endClippedLayout );
309
+ }
298
310
}
299
311
300
312
private void updateNodeVisibility () {
@@ -413,45 +425,43 @@ private RNSharedElementStyle getInterpolatedStyle(
413
425
return result ;
414
426
}
415
427
416
- private void fireMeasureEvent () {
417
- /*ReactContext reactContext = (ReactContext)getContext();
418
- WritableMap eventData = Arguments.createMap();
428
+ private void fireMeasureEvent (String name , RNSharedElementTransitionItem item , Rect clippedLayout ) {
429
+ ReactContext reactContext = (ReactContext )getContext ();
430
+ RNSharedElementStyle style = item .getStyle ();
431
+ RNSharedElementContent content = item .getContent ();
432
+
419
433
WritableMap layoutData = Arguments .createMap ();
420
- layoutData.putFloat();
421
- //eventData.putString("message", "MyMessage");
422
- eventData.putString("node", item.name);
423
- eventData.putMap("layout", layoutData)
434
+ layoutData .putDouble ("x" , PixelUtil .toDIPFromPixel (style .layout .left ));
435
+ layoutData .putDouble ("y" , PixelUtil .toDIPFromPixel (style .layout .top ));
436
+ layoutData .putDouble ("width" , PixelUtil .toDIPFromPixel (style .layout .width ()));
437
+ layoutData .putDouble ("height" , PixelUtil .toDIPFromPixel (style .layout .height ()));
438
+ layoutData .putDouble ("visibleX" , PixelUtil .toDIPFromPixel (clippedLayout .left ));
439
+ layoutData .putDouble ("visibleY" , PixelUtil .toDIPFromPixel (clippedLayout .top ));
440
+ layoutData .putDouble ("visibleWidth" , PixelUtil .toDIPFromPixel (clippedLayout .width ()));
441
+ layoutData .putDouble ("visibleHeight" , PixelUtil .toDIPFromPixel (clippedLayout .height ()));
442
+ layoutData .putDouble ("contentX" , PixelUtil .toDIPFromPixel (style .layout .left )); // TODO
443
+ layoutData .putDouble ("contentY" , PixelUtil .toDIPFromPixel (style .layout .top )); // TODO
444
+ layoutData .putDouble ("contentWidth" , PixelUtil .toDIPFromPixel (style .layout .width ())); // TODO
445
+ layoutData .putDouble ("contentHeight" , PixelUtil .toDIPFromPixel (style .layout .height ())); // TODO
446
+
447
+ WritableMap styleData = Arguments .createMap ();
448
+ styleData .putDouble ("borderTopLeftRadius" , PixelUtil .toDIPFromPixel (style .borderTopLeftRadius ));
449
+ styleData .putDouble ("borderTopRightRadius" , PixelUtil .toDIPFromPixel (style .borderTopRightRadius ));
450
+ styleData .putDouble ("borderBottomLeftRadius" , PixelUtil .toDIPFromPixel (style .borderBottomLeftRadius ));
451
+ styleData .putDouble ("borderBottomRightRadius" , PixelUtil .toDIPFromPixel (style .borderBottomRightRadius ));
452
+
453
+ WritableMap eventData = Arguments .createMap ();
454
+ eventData .putString ("node" , name );
455
+ eventData .putMap ("layout" , layoutData );
456
+ RNSharedElementDrawable .ViewType viewType = (content != null )
457
+ ? RNSharedElementDrawable .getViewType (content .view , style )
458
+ : RNSharedElementDrawable .ViewType .NONE ;
459
+ eventData .putString ("contentType" , viewType .getValue ());
460
+ eventData .putMap ("style" , styleData );
461
+
424
462
reactContext .getJSModule (RCTEventEmitter .class ).receiveEvent (
425
463
getId (),
426
- "onMeasure",
427
- eventData);*/
428
-
429
- /*
430
- - (void) fireMeasureEvent:(RNSharedElementTransitionItem*) item layout:(CGRect)layout visibleLayout:(CGRect)visibleLayout contentLayout:(CGRect)contentLayout
431
- {
432
- if (!self.onMeasureNode) return;
433
- NSDictionary* eventData = @{
434
- @"node": item.name,
435
- @"layout": @{
436
- @"x": @(layout.origin.x),
437
- @"y": @(layout.origin.y),
438
- @"width": @(layout.size.width),
439
- @"height": @(layout.height()),
440
- @"visibleX": @(visibleLayout.origin.x),
441
- @"visibleY": @(visibleLayout.origin.y),
442
- @"visibleWidth": @(visibleLayout.size.width),
443
- @"visibleHeight": @(visibleLayout.height()),
444
- @"contentX": @(contentLayout.origin.x),
445
- @"contentY": @(contentLayout.origin.y),
446
- @"contentWidth": @(contentLayout.size.width),
447
- @"contentHeight": @(contentLayout.height()),
448
- },
449
- @"contentType": item.contentTypeName,
450
- @"style": @{
451
- @"borderRadius": @(item.style.cornerRadius)
452
- }
453
- };
454
- self.onMeasureNode(eventData);
455
- }*/
464
+ "onMeasureNode" ,
465
+ eventData );
456
466
}
457
467
}
0 commit comments