-
Notifications
You must be signed in to change notification settings - Fork 0
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
5f65488
commit 7f19bd8
Showing
4 changed files
with
70 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// source from react-native-anchor-point | ||
// I extracted the code included in the node module because I assumed it was not included in the integrated build. | ||
import type { TransformsStyle } from 'react-native'; | ||
|
||
export interface Point { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export interface Size { | ||
width: number; | ||
height: number; | ||
} | ||
|
||
const isValidSize = (size: Size): boolean => { | ||
return size && size.width > 0 && size.height > 0; | ||
}; | ||
|
||
const defaultAnchorPoint = { x: 0.5, y: 0.5 }; | ||
|
||
export const withAnchorPoint = ( | ||
transform: TransformsStyle, | ||
anchorPoint: Point, | ||
size: Size | ||
) => { | ||
if (!isValidSize(size)) { | ||
return transform; | ||
} | ||
|
||
let injectedTransform = transform.transform; | ||
if (!injectedTransform) { | ||
return transform; | ||
} | ||
|
||
if (anchorPoint.x !== defaultAnchorPoint.x && size.width) { | ||
const shiftTranslateX = []; | ||
|
||
// shift before rotation | ||
shiftTranslateX.push({ | ||
translateX: size.width * (anchorPoint.x - defaultAnchorPoint.x), | ||
}); | ||
// @ts-ignore | ||
injectedTransform = [...shiftTranslateX, ...injectedTransform]; | ||
// shift after rotation | ||
// @ts-ignore | ||
injectedTransform.push({ | ||
translateX: size.width * (defaultAnchorPoint.x - anchorPoint.x), | ||
}); | ||
} | ||
|
||
if (!Array.isArray(injectedTransform)) { | ||
return { transform: injectedTransform }; | ||
} | ||
|
||
if (anchorPoint.y !== defaultAnchorPoint.y && size.height) { | ||
let shiftTranslateY = []; | ||
// shift before rotation | ||
shiftTranslateY.push({ | ||
translateY: size.height * (anchorPoint.y - defaultAnchorPoint.y), | ||
}); | ||
injectedTransform = [...shiftTranslateY, ...injectedTransform]; | ||
// shift after rotation | ||
injectedTransform.push({ | ||
translateY: size.height * (defaultAnchorPoint.y - anchorPoint.y), | ||
}); | ||
} | ||
|
||
return { transform: injectedTransform }; | ||
}; |
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