-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82f0f3a
commit 3bcd041
Showing
8 changed files
with
222 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2015-present, Horcrux. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.horcrux.svg; | ||
|
||
import com.facebook.react.uimanager.annotations.ReactProp; | ||
import com.facebook.react.views.text.ReactBaseTextShadowNode; | ||
import com.facebook.yoga.YogaMeasureFunction; | ||
import com.facebook.yoga.YogaMeasureMode; | ||
import com.facebook.yoga.YogaMeasureOutput; | ||
import com.facebook.yoga.YogaNode; | ||
|
||
public class SvgShadowNode extends ReactBaseTextShadowNode implements YogaMeasureFunction { | ||
private float mVbWidth = 0; | ||
private float mVbHeight = 0; | ||
|
||
public SvgShadowNode() { | ||
setMeasureFunction(this); | ||
} | ||
|
||
@ReactProp(name = "vbWidth") | ||
public void setVbWidth(float vbWidth) { | ||
mVbWidth = vbWidth; | ||
} | ||
|
||
@ReactProp(name = "vbHeight") | ||
public void setVbHeight(float vbHeight) { | ||
mVbHeight = vbHeight; | ||
} | ||
|
||
@Override | ||
public long measure( | ||
YogaNode node, | ||
float baseWidth, | ||
YogaMeasureMode widthMode, | ||
float baseHeight, | ||
YogaMeasureMode heightMode) { | ||
|
||
float width = baseWidth; | ||
float height = baseHeight; | ||
float maxWidth = widthMode == YogaMeasureMode.AT_MOST ? width : Float.MAX_VALUE; | ||
float maxHeight = heightMode == YogaMeasureMode.AT_MOST ? height : Float.MAX_VALUE; | ||
|
||
if (mVbWidth != 0 && mVbHeight != 0) { | ||
if (widthMode != YogaMeasureMode.EXACTLY) { | ||
width = Math.min(mVbWidth / mVbHeight * height, maxWidth); | ||
} | ||
if (heightMode != YogaMeasureMode.EXACTLY) { | ||
height = Math.min(mVbHeight / mVbWidth * width, maxHeight); | ||
} | ||
} | ||
|
||
return YogaMeasureOutput.make(width, height); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (c) 2015-present, Horcrux. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import <React/RCTShadowView.h> | ||
|
||
@class RCTBridge; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RNSVGSvgShadowView : RCTShadowView | ||
|
||
@property (nonatomic, assign) CGFloat vbWidth; | ||
@property (nonatomic, assign) CGFloat vbHeight; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2015-present, Horcrux. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RNSVGSvgShadowView.h" | ||
|
||
@implementation RNSVGSvgShadowView | ||
|
||
- (instancetype)init | ||
{ | ||
if (self = [super init]) { | ||
YGNodeSetMeasureFunc(self.yogaNode, RNSVGSvgShadowViewMeasure); | ||
} | ||
|
||
return self; | ||
} | ||
|
||
static YGSize RNSVGSvgShadowViewMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) | ||
{ | ||
RNSVGSvgShadowView *shadowView = (__bridge RNSVGSvgShadowView *)YGNodeGetContext(node); | ||
|
||
CGSize size = {width, height}; | ||
CGSize maximumSize = { | ||
widthMode == YGMeasureModeAtMost ? size.width : CGFLOAT_MAX, | ||
heightMode == YGMeasureModeAtMost ? size.height : CGFLOAT_MAX, | ||
}; | ||
if (shadowView.vbWidth != 0 && shadowView.vbHeight != 0) { | ||
if (widthMode != YGMeasureModeExactly) { | ||
size.width = MIN(shadowView.vbWidth / shadowView.vbHeight * size.height, maximumSize.width); | ||
} | ||
if (heightMode != YGMeasureModeExactly) { | ||
size.height = MIN(shadowView.vbHeight / shadowView.vbWidth * size.width, maximumSize.height); | ||
} | ||
} | ||
|
||
return (YGSize){ | ||
RCTYogaFloatFromCoreGraphicsFloat(size.width), | ||
RCTYogaFloatFromCoreGraphicsFloat(size.height), | ||
}; | ||
} | ||
|
||
- (BOOL)isYogaLeafNode | ||
{ | ||
return YES; | ||
} | ||
|
||
- (void)layoutSubviewsWithContext:(RCTLayoutContext)layoutContext | ||
{ | ||
// Do nothing. | ||
} | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters