mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
refactor: inline extractClipPath as it's only used in one place now
This commit is contained in:
@@ -15,7 +15,7 @@ const {
|
|||||||
export default {
|
export default {
|
||||||
...Mixin,
|
...Mixin,
|
||||||
|
|
||||||
touchableHandleStartShouldSetResponder: function(e: GestureResponderEvent) {
|
touchableHandleStartShouldSetResponder(e: GestureResponderEvent) {
|
||||||
const { onStartShouldSetResponder } = this.props;
|
const { onStartShouldSetResponder } = this.props;
|
||||||
if (onStartShouldSetResponder) {
|
if (onStartShouldSetResponder) {
|
||||||
return onStartShouldSetResponder(e);
|
return onStartShouldSetResponder(e);
|
||||||
@@ -24,9 +24,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleResponderTerminationRequest: function(
|
touchableHandleResponderTerminationRequest(e: GestureResponderEvent) {
|
||||||
e: GestureResponderEvent,
|
|
||||||
) {
|
|
||||||
const { onResponderTerminationRequest } = this.props;
|
const { onResponderTerminationRequest } = this.props;
|
||||||
if (onResponderTerminationRequest) {
|
if (onResponderTerminationRequest) {
|
||||||
return onResponderTerminationRequest(e);
|
return onResponderTerminationRequest(e);
|
||||||
@@ -35,7 +33,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleResponderGrant: function(e: GestureResponderEvent) {
|
touchableHandleResponderGrant(e: GestureResponderEvent) {
|
||||||
const { onResponderGrant } = this.props;
|
const { onResponderGrant } = this.props;
|
||||||
if (onResponderGrant) {
|
if (onResponderGrant) {
|
||||||
return onResponderGrant(e);
|
return onResponderGrant(e);
|
||||||
@@ -44,7 +42,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleResponderMove: function(e: GestureResponderEvent) {
|
touchableHandleResponderMove(e: GestureResponderEvent) {
|
||||||
const { onResponderMove } = this.props;
|
const { onResponderMove } = this.props;
|
||||||
if (onResponderMove) {
|
if (onResponderMove) {
|
||||||
return onResponderMove(e);
|
return onResponderMove(e);
|
||||||
@@ -53,7 +51,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleResponderRelease: function(e: GestureResponderEvent) {
|
touchableHandleResponderRelease(e: GestureResponderEvent) {
|
||||||
const { onResponderRelease } = this.props;
|
const { onResponderRelease } = this.props;
|
||||||
if (onResponderRelease) {
|
if (onResponderRelease) {
|
||||||
return onResponderRelease(e);
|
return onResponderRelease(e);
|
||||||
@@ -62,7 +60,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleResponderTerminate: function(e: GestureResponderEvent) {
|
touchableHandleResponderTerminate(e: GestureResponderEvent) {
|
||||||
const { onResponderTerminate } = this.props;
|
const { onResponderTerminate } = this.props;
|
||||||
if (onResponderTerminate) {
|
if (onResponderTerminate) {
|
||||||
return onResponderTerminate(e);
|
return onResponderTerminate(e);
|
||||||
@@ -71,47 +69,47 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandlePress: function(e: GestureResponderEvent) {
|
touchableHandlePress(e: GestureResponderEvent) {
|
||||||
const { onPress } = this.props;
|
const { onPress } = this.props;
|
||||||
onPress && onPress(e);
|
onPress && onPress(e);
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleActivePressIn: function(e: GestureResponderEvent) {
|
touchableHandleActivePressIn(e: GestureResponderEvent) {
|
||||||
const { onPressIn } = this.props;
|
const { onPressIn } = this.props;
|
||||||
onPressIn && onPressIn(e);
|
onPressIn && onPressIn(e);
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleActivePressOut: function(e: GestureResponderEvent) {
|
touchableHandleActivePressOut(e: GestureResponderEvent) {
|
||||||
const { onPressOut } = this.props;
|
const { onPressOut } = this.props;
|
||||||
onPressOut && onPressOut(e);
|
onPressOut && onPressOut(e);
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableHandleLongPress: function(e: GestureResponderEvent) {
|
touchableHandleLongPress(e: GestureResponderEvent) {
|
||||||
const { onLongPress } = this.props;
|
const { onLongPress } = this.props;
|
||||||
onLongPress && onLongPress(e);
|
onLongPress && onLongPress(e);
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableGetPressRectOffset: function() {
|
touchableGetPressRectOffset() {
|
||||||
const { pressRetentionOffset } = this.props;
|
const { pressRetentionOffset } = this.props;
|
||||||
return pressRetentionOffset || PRESS_RETENTION_OFFSET;
|
return pressRetentionOffset || PRESS_RETENTION_OFFSET;
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableGetHitSlop: function() {
|
touchableGetHitSlop() {
|
||||||
const { hitSlop } = this.props;
|
const { hitSlop } = this.props;
|
||||||
return hitSlop;
|
return hitSlop;
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableGetHighlightDelayMS: function() {
|
touchableGetHighlightDelayMS() {
|
||||||
const { delayPressIn } = this.props;
|
const { delayPressIn } = this.props;
|
||||||
return delayPressIn || 0;
|
return delayPressIn || 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableGetLongPressDelayMS: function() {
|
touchableGetLongPressDelayMS() {
|
||||||
const { delayLongPress } = this.props;
|
const { delayLongPress } = this.props;
|
||||||
return delayLongPress === 0 ? 0 : delayLongPress || 500;
|
return delayLongPress === 0 ? 0 : delayLongPress || 500;
|
||||||
},
|
},
|
||||||
|
|
||||||
touchableGetPressOutDelayMS: function() {
|
touchableGetPressOutDelayMS() {
|
||||||
const { delayPressOut } = this.props;
|
const { delayPressOut } = this.props;
|
||||||
return delayPressOut || 0;
|
return delayPressOut || 0;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
import { idPattern } from '../util';
|
|
||||||
import { ClipProps } from './types';
|
|
||||||
|
|
||||||
const clipRules: { evenodd: number; nonzero: number } = {
|
|
||||||
evenodd: 0,
|
|
||||||
nonzero: 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function extractClipPath(props: ClipProps) {
|
|
||||||
const { clipPath, clipRule } = props;
|
|
||||||
const extracted: {
|
|
||||||
clipPath?: string;
|
|
||||||
clipRule?: number;
|
|
||||||
} = {};
|
|
||||||
|
|
||||||
if (clipRule) {
|
|
||||||
extracted.clipRule = clipRules[clipRule] === 0 ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clipPath) {
|
|
||||||
const matched = clipPath.match(idPattern);
|
|
||||||
|
|
||||||
if (matched) {
|
|
||||||
extracted.clipPath = matched[1];
|
|
||||||
} else {
|
|
||||||
console.warn(
|
|
||||||
'Invalid `clipPath` prop, expected a clipPath like "#id", but got: "' +
|
|
||||||
clipPath +
|
|
||||||
'"',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return extracted;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import extractFill from './extractFill';
|
import extractFill from './extractFill';
|
||||||
import extractStroke from './extractStroke';
|
import extractStroke from './extractStroke';
|
||||||
import { transformToMatrix, props2transform } from './extractTransform';
|
import { transformToMatrix, props2transform } from './extractTransform';
|
||||||
import extractClipPath from './extractClipPath';
|
|
||||||
import extractResponder from './extractResponder';
|
import extractResponder from './extractResponder';
|
||||||
import extractOpacity from './extractOpacity';
|
import extractOpacity from './extractOpacity';
|
||||||
import { idPattern } from '../util';
|
import { idPattern } from '../util';
|
||||||
@@ -15,6 +14,11 @@ import {
|
|||||||
} from './types';
|
} from './types';
|
||||||
import { Component } from 'react';
|
import { Component } from 'react';
|
||||||
|
|
||||||
|
const clipRules: { evenodd: number; nonzero: number } = {
|
||||||
|
evenodd: 0,
|
||||||
|
nonzero: 1,
|
||||||
|
};
|
||||||
|
|
||||||
export function propsAndStyles(props: Object & { style?: [] | {} }) {
|
export function propsAndStyles(props: Object & { style?: [] | {} }) {
|
||||||
const { style } = props;
|
const { style } = props;
|
||||||
return !style
|
return !style
|
||||||
@@ -57,6 +61,7 @@ export default function extractProps(
|
|||||||
onLayout,
|
onLayout,
|
||||||
id,
|
id,
|
||||||
clipPath,
|
clipPath,
|
||||||
|
clipRule,
|
||||||
mask,
|
mask,
|
||||||
marker,
|
marker,
|
||||||
markerStart = marker,
|
markerStart = marker,
|
||||||
@@ -78,12 +83,10 @@ export default function extractProps(
|
|||||||
markerStart?: string;
|
markerStart?: string;
|
||||||
markerMid?: string;
|
markerMid?: string;
|
||||||
markerEnd?: string;
|
markerEnd?: string;
|
||||||
|
clipPath?: string;
|
||||||
|
clipRule?: number;
|
||||||
} = {
|
} = {
|
||||||
matrix,
|
matrix,
|
||||||
markerStart: getMarker(markerStart),
|
|
||||||
markerMid: getMarker(markerMid),
|
|
||||||
markerEnd: getMarker(markerEnd),
|
|
||||||
onLayout,
|
|
||||||
...transformProps,
|
...transformProps,
|
||||||
propList: styleProperties,
|
propList: styleProperties,
|
||||||
opacity: extractOpacity(opacity),
|
opacity: extractOpacity(opacity),
|
||||||
@@ -92,12 +95,42 @@ export default function extractProps(
|
|||||||
...extractStroke(props, styleProperties),
|
...extractStroke(props, styleProperties),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (onLayout) {
|
||||||
|
extracted.onLayout = onLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (markerStart) {
|
||||||
|
extracted.markerStart = getMarker(markerStart);
|
||||||
|
}
|
||||||
|
if (markerMid) {
|
||||||
|
extracted.markerMid = getMarker(markerMid);
|
||||||
|
}
|
||||||
|
if (markerEnd) {
|
||||||
|
extracted.markerEnd = getMarker(markerEnd);
|
||||||
|
}
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
extracted.name = String(id);
|
extracted.name = String(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clipPath) {
|
if (clipPath) {
|
||||||
Object.assign(extracted, extractClipPath(props));
|
if (clipRule) {
|
||||||
|
extracted.clipRule = clipRules[clipRule] === 0 ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clipPath) {
|
||||||
|
const matched = clipPath.match(idPattern);
|
||||||
|
|
||||||
|
if (matched) {
|
||||||
|
extracted.clipPath = matched[1];
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
'Invalid `clipPath` prop, expected a clipPath like "#id", but got: "' +
|
||||||
|
clipPath +
|
||||||
|
'"',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask) {
|
if (mask) {
|
||||||
|
|||||||
Reference in New Issue
Block a user