private static @Nullable TransitionId getTransitionIdForNode(InternalNode node) { @TransitionId.Type int type; String reference; String extraData = null; if (node.hasTransitionKey()) { Transition.TransitionKeyType transitionKeyType = node.getTransitionKeyType(); if (transitionKeyType == Transition.TransitionKeyType.GLOBAL) { type = TransitionId.Type.GLOBAL; } else if (transitionKeyType == Transition.TransitionKeyType.LOCAL) { type = TransitionId.Type.SCOPED; extraData = node.getRootComponent().getOwnerGlobalKey(); } else { throw new RuntimeException("Unhandled transition key type " + transitionKeyType); } reference = node.getTransitionKey(); } else if (ComponentsConfiguration.assignTransitionKeysToAllOutputs) { type = TransitionId.Type.AUTOGENERATED; reference = node.getRootComponent().getGlobalKey(); } else { return null; } return reference != null ? new TransitionId(type, reference, extraData) : null; } }
@Test public void testOwnerGlobalKey() { final Component root = getMultipleChildrenComponent(); final int layoutSpecId = root.getTypeId(); final int nestedLayoutSpecId = layoutSpecId - 1; final int columnSpecId = Column.create(mContext).build().getTypeId(); final LithoView lithoView = getLithoView(root); final String rootGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId); final String nestedLayoutGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId, columnSpecId, nestedLayoutSpecId); // Text Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 0).getOwnerGlobalKey()); // TestViewComponent in child layout Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 1).getOwnerGlobalKey()); // CardClip in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 3).getOwnerGlobalKey()); // Text in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 4).getOwnerGlobalKey()); // CardClip Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 6).getOwnerGlobalKey()); // TestViewComponent Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 7).getOwnerGlobalKey()); }
@Test public void testOwnerGlobalKey() { final Component root = getMultipleChildrenComponent(); final int layoutSpecId = root.getTypeId(); final int nestedLayoutSpecId = layoutSpecId - 1; final int columnSpecId = Column.create(mContext).build().getTypeId(); final LithoView lithoView = getLithoView(root); final String rootGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId); final String nestedLayoutGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId, columnSpecId, nestedLayoutSpecId); // Text Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 0).getOwnerGlobalKey()); // TestViewComponent in child layout Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 1).getOwnerGlobalKey()); // CardClip in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 3).getOwnerGlobalKey()); // Text in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 4).getOwnerGlobalKey()); // CardClip Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 6).getOwnerGlobalKey()); // TestViewComponent Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 7).getOwnerGlobalKey()); }