package org.vovkasm.WebImage;

import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.Spacing;
import com.facebook.react.uimanager.UIViewOperationQueue;
import com.facebook.yoga.YogaConstants;

import java.util.Arrays;

class WebImageShadowNode extends LayoutShadowNode {
    private float[] mBorderWidths = new float[Spacing.ALL+1];

    WebImageShadowNode() {
        super();
        Arrays.fill(mBorderWidths, YogaConstants.UNDEFINED);
    }

    @Override
    public void setBorder(int spacingType, float borderWidth) {
        super.setBorder(spacingType, borderWidth);
        mBorderWidths[spacingType] = borderWidth;
    }

    private float getEffectiveBorderWidth(int spacing) {
        float width = mBorderWidths[spacing];
        if (YogaConstants.isUndefined(width)) width = mBorderWidths[Spacing.ALL];
        if (YogaConstants.isUndefined(width)) width = 0.0f;
        return width;
    }

    @Override
    public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) {
        super.onCollectExtraUpdates(uiViewOperationQueue);
        BoxMetrics bm = new BoxMetrics(
                getLayoutWidth(),
                getLayoutHeight(),
                getEffectiveBorderWidth(Spacing.LEFT),
                getEffectiveBorderWidth(Spacing.TOP),
                getEffectiveBorderWidth(Spacing.RIGHT),
                getEffectiveBorderWidth(Spacing.BOTTOM),
                getPadding(Spacing.LEFT),
                getPadding(Spacing.TOP),
                getPadding(Spacing.RIGHT),
                getPadding(Spacing.BOTTOM)
        );
        uiViewOperationQueue.enqueueUpdateExtraData(getReactTag(), bm);
    }

}

@@ -1240,35 +1240,36 @@
 erWidth(Spacing.
-LEF
+STAR
 T),%0A            
@@ -1350,37 +1350,35 @@
 erWidth(Spacing.
-RIGHT
+END
 ),%0A             

Fix border horizontal dimensions.