void setFromDynamic(Dynamic dynamic) { if (dynamic.isNull()) { unit = YogaUnit.UNDEFINED; value = YogaConstants.UNDEFINED; } else if (dynamic.getType() == ReadableType.String) { final String s = dynamic.asString(); if (s.equals("auto")) { unit = YogaUnit.AUTO; value = YogaConstants.UNDEFINED; } else if (s.endsWith("%")) { unit = YogaUnit.PERCENT; value = Float.parseFloat(s.substring(0, s.length() - 1)); } else { throw new IllegalArgumentException("Unknown value: " + s); } } else { unit = YogaUnit.POINT; value = PixelUtil.toPixelFromDIP(dynamic.asDouble()); } }
@ReactProp(name = ViewProps.WIDTH) public void setWidth(Dynamic width) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(width); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setStyleWidth(mTempYogaValue.value); break; case AUTO: setStyleWidthAuto(); break; case PERCENT: setStyleWidthPercent(mTempYogaValue.value); break; } width.recycle(); }
@ReactProp(name = ViewProps.MIN_WIDTH) public void setMinWidth(Dynamic minWidth) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(minWidth); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setStyleMinWidth(mTempYogaValue.value); break; case PERCENT: setStyleMinWidthPercent(mTempYogaValue.value); break; } minWidth.recycle(); }
@ReactProp(name = ViewProps.MAX_WIDTH) public void setMaxWidth(Dynamic maxWidth) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(maxWidth); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setStyleMaxWidth(mTempYogaValue.value); break; case PERCENT: setStyleMaxWidthPercent(mTempYogaValue.value); break; } maxWidth.recycle(); }
@ReactProp(name = ViewProps.HEIGHT) public void setHeight(Dynamic height) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(height); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setStyleHeight(mTempYogaValue.value); break; case AUTO: setStyleHeightAuto(); break; case PERCENT: setStyleHeightPercent(mTempYogaValue.value); break; } height.recycle(); }
@ReactProp(name = ViewProps.MIN_HEIGHT) public void setMinHeight(Dynamic minHeight) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(minHeight); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setStyleMinHeight(mTempYogaValue.value); break; case PERCENT: setStyleMinHeightPercent(mTempYogaValue.value); break; } minHeight.recycle(); }
@ReactProp(name = ViewProps.MAX_HEIGHT) public void setMaxHeight(Dynamic maxHeight) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(maxHeight); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setStyleMaxHeight(mTempYogaValue.value); break; case PERCENT: setStyleMaxHeightPercent(mTempYogaValue.value); break; } maxHeight.recycle(); }
@ReactProp(name = ViewProps.FLEX_BASIS) public void setFlexBasis(Dynamic flexBasis) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(flexBasis); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setFlexBasis(mTempYogaValue.value); break; case AUTO: setFlexBasisAuto(); break; case PERCENT: setFlexBasisPercent(mTempYogaValue.value); break; } flexBasis.recycle(); }
@ReactPropGroup(names = { ViewProps.LEFT, ViewProps.RIGHT, ViewProps.TOP, ViewProps.BOTTOM, }) public void setPositionValues(int index, Dynamic position) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(position); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setPosition(ViewProps.POSITION_SPACING_TYPES[index], mTempYogaValue.value); break; case PERCENT: setPositionPercent(ViewProps.POSITION_SPACING_TYPES[index], mTempYogaValue.value); break; } position.recycle(); }
@ReactMethod public void findAllEvents(final Dynamic startDate, final Dynamic endDate, final ReadableArray calendars, final Promise promise) { if (this.haveCalendarReadWritePermissions()) { try { Thread thread = new Thread(new Runnable(){ @Override public void run() { WritableNativeArray results = findEvents(startDate, endDate, calendars); promise.resolve(results); } }); thread.start(); } catch (Exception e) { promise.reject("find event error", e.getMessage()); } } else { promise.reject("find event error", "you don't have permissions to read an event from the users calendar"); } }
/** * Besides width/height, all other layout props on inline images are ignored */ @Override public void setWidth(Dynamic width) { if (width.getType() == ReadableType.Number) { mWidth = (float) width.asDouble(); } else { throw new JSApplicationIllegalArgumentException( "Inline images must not have percentage based width"); } }
@Override public void setHeight(Dynamic height) { if (height.getType() == ReadableType.Number) { mHeight = (float) height.asDouble(); } else { throw new JSApplicationIllegalArgumentException( "Inline images must not have percentage based height"); } }
@ReactPropGroup(names = { ViewProps.MARGIN, ViewProps.MARGIN_VERTICAL, ViewProps.MARGIN_HORIZONTAL, ViewProps.MARGIN_LEFT, ViewProps.MARGIN_RIGHT, ViewProps.MARGIN_TOP, ViewProps.MARGIN_BOTTOM, }) public void setMargins(int index, Dynamic margin) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(margin); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setMargin(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value); break; case AUTO: setMarginAuto(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]); break; case PERCENT: setMarginPercent(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value); break; } margin.recycle(); }
@ReactPropGroup(names = { ViewProps.PADDING, ViewProps.PADDING_VERTICAL, ViewProps.PADDING_HORIZONTAL, ViewProps.PADDING_LEFT, ViewProps.PADDING_RIGHT, ViewProps.PADDING_TOP, ViewProps.PADDING_BOTTOM, }) public void setPaddings(int index, Dynamic padding) { if (isVirtual()) { return; } mTempYogaValue.setFromDynamic(padding); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: setPadding(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value); break; case PERCENT: setPaddingPercent(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value); break; } padding.recycle(); }
private static PropSetter createPropSetter( ReactProp annotation, Method method, Class<?> propTypeClass) { if (propTypeClass == Dynamic.class) { return new DynamicPropSetter(annotation, method); } else if (propTypeClass == boolean.class) { return new BooleanPropSetter(annotation, method, annotation.defaultBoolean()); } else if (propTypeClass == int.class) { return new IntPropSetter(annotation, method, annotation.defaultInt()); } else if (propTypeClass == float.class) { return new FloatPropSetter(annotation, method, annotation.defaultFloat()); } else if (propTypeClass == double.class) { return new DoublePropSetter(annotation, method, annotation.defaultDouble()); } else if (propTypeClass == String.class) { return new StringPropSetter(annotation, method); } else if (propTypeClass == Boolean.class) { return new BoxedBooleanPropSetter(annotation, method); } else if (propTypeClass == Integer.class) { return new BoxedIntPropSetter(annotation, method); } else if (propTypeClass == ReadableArray.class) { return new ArrayPropSetter(annotation, method); } else if (propTypeClass == ReadableMap.class) { return new MapPropSetter(annotation, method); } else { throw new RuntimeException("Unrecognized type: " + propTypeClass + " for method: " + method.getDeclaringClass().getName() + "#" + method.getName()); } }
public void testDynamicType() { mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnDynamicTypes(); waitForBridgeAndUIIdle(); List<Dynamic> dynamicCalls = mRecordingTestModule.getDynamicCalls(); assertEquals(2, dynamicCalls.size()); assertEquals("foo", dynamicCalls.get(0).asString()); assertEquals(3.14, dynamicCalls.get(1).asDouble()); }
@Nullable public Dynamic getDynamic(String key) { return mBackingMap.getDynamic(key); }
private static void createPropSetters( ReactPropGroup annotation, Method method, Class<?> propTypeClass, Map<String, PropSetter> props) { String[] names = annotation.names(); if (propTypeClass == Dynamic.class) { for (int i = 0; i < names.length; i++) { props.put( names[i], new DynamicPropSetter(annotation, method, i)); } } else if (propTypeClass == int.class) { for (int i = 0; i < names.length; i++) { props.put( names[i], new IntPropSetter(annotation, method, i, annotation.defaultInt())); } } else if (propTypeClass == float.class) { for (int i = 0; i < names.length; i++) { props.put( names[i], new FloatPropSetter(annotation, method, i, annotation.defaultFloat())); } } else if (propTypeClass == double.class) { for (int i = 0; i < names.length; i++) { props.put( names[i], new DoublePropSetter(annotation, method, i, annotation.defaultDouble())); } } else if (propTypeClass == Integer.class) { for (int i = 0; i < names.length; i++) { props.put( names[i], new BoxedIntPropSetter(annotation, method, i)); } } else { throw new RuntimeException("Unrecognized type: " + propTypeClass + " for method: " + method.getDeclaringClass().getName() + "#" + method.getName()); } }
@ReactMethod public void receiveDynamic(Dynamic dynamic) { mDynamicCalls.add(dynamic); }
public List<Dynamic> getDynamicCalls() { return mDynamicCalls; }
@Override public Dynamic getDynamic(String name) { return (Dynamic) this.get(name); }