Skip to content

Commit f1acab7

Browse files
committed
feat: add clip-path js support
1 parent 2ac5488 commit f1acab7

9 files changed

Lines changed: 2157 additions & 39 deletions

File tree

packages/react-native/Libraries/Components/View/ReactNativeStyleAttributes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import processBackgroundPosition from '../../StyleSheet/processBackgroundPositio
1717
import processBackgroundRepeat from '../../StyleSheet/processBackgroundRepeat';
1818
import processBackgroundSize from '../../StyleSheet/processBackgroundSize';
1919
import processBoxShadow from '../../StyleSheet/processBoxShadow';
20+
import processClipPath from '../../StyleSheet/processClipPath';
2021
import processColor from '../../StyleSheet/processColor';
2122
import processFilter from '../../StyleSheet/processFilter';
2223
import processFontVariant from '../../StyleSheet/processFontVariant';
@@ -203,7 +204,9 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
203204
outlineStyle: true,
204205
outlineWidth: true,
205206
pointerEvents: true,
206-
207+
clipPath: ReactNativeFeatureFlags.enableNativeCSSParsing()
208+
? true
209+
: {process: processClipPath},
207210
/**
208211
* Text
209212
*/

packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ const validAttributesForNonEventProps = {
357357
borderStyle: true,
358358
hitSlop: true,
359359
pointerEvents: true,
360+
clipPath: true,
360361
nativeBackgroundAndroid: true,
361362
nativeForegroundAndroid: true,
362363
needsOffscreenAlphaCompositing: true,

packages/react-native/Libraries/StyleSheet/StyleSheetTypes.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,85 @@ export type BoxShadowValue = {
825825
inset?: boolean,
826826
};
827827

828+
export type ClipPathGeometryBox =
829+
| 'border-box'
830+
| 'padding-box'
831+
| 'content-box'
832+
| 'margin-box'
833+
| 'fill-box'
834+
| 'stroke-box'
835+
| 'view-box';
836+
837+
export type ClipPathFillRule = 'nonzero' | 'evenodd';
838+
839+
export type ClipPathInsetShape = {
840+
type: 'inset',
841+
top?: number | string | null,
842+
bottom?: number | string | null,
843+
left?: number | string | null,
844+
right?: number | string | null,
845+
borderRadius?: number | string | null,
846+
...
847+
};
848+
849+
export type ClipPathCircleShape = {
850+
type: 'circle',
851+
r?: number | string | null,
852+
cx?: number | string | null,
853+
cy?: number | string | null,
854+
...
855+
};
856+
857+
export type ClipPathEllipseShape = {
858+
type: 'ellipse',
859+
rx?: number | string | null,
860+
ry?: number | string | null,
861+
cx?: number | string | null,
862+
cy?: number | string | null,
863+
...
864+
};
865+
866+
export type ClipPathPolygonShape = {
867+
type: 'polygon',
868+
points: $ReadOnlyArray<{x: number | string, y: number | string, ...}>,
869+
fillRule?: ClipPathFillRule | null,
870+
...
871+
};
872+
873+
export type ClipPathRectShape = {
874+
type: 'rect',
875+
top: number | string | 'auto',
876+
right: number | string | 'auto',
877+
bottom: number | string | 'auto',
878+
left: number | string | 'auto',
879+
borderRadius?: number | string | null,
880+
...
881+
};
882+
883+
export type ClipPathXywhShape = {
884+
type: 'xywh',
885+
x: number | string,
886+
y: number | string,
887+
width: number | string,
888+
height: number | string,
889+
borderRadius?: number | string | null,
890+
...
891+
};
892+
893+
export type ClipPathBasicShape =
894+
| ClipPathInsetShape
895+
| ClipPathCircleShape
896+
| ClipPathEllipseShape
897+
| ClipPathPolygonShape
898+
| ClipPathRectShape
899+
| ClipPathXywhShape;
900+
901+
export type ClipPathValue = {
902+
shape?: ClipPathBasicShape | null,
903+
geometryBox?: ClipPathGeometryBox | null,
904+
...
905+
};
906+
828907
type ____BlendMode_Internal =
829908
| 'normal'
830909
| 'multiply'
@@ -898,6 +977,7 @@ export type ____ViewStyle_InternalBase = $ReadOnly<{
898977
| $ReadOnlyArray<BackgroundRepeatValue>
899978
| string,
900979
isolation?: 'auto' | 'isolate',
980+
clipPath?: ClipPathValue | string,
901981
}>;
902982

903983
export type ____ViewStyle_InternalCore = $ReadOnly<{

0 commit comments

Comments
 (0)