React Native Transform Origin

▼魔方 西西 提交于 2020-06-27 06:45:26

问题


how do I apply the transform-origin property to a style in react native? I've tried in several ways, but I did not get an event

I tried:

transform: [{ rotate: ('90deg')},{origin: {x: 'top', y:'center'}} ]

回答1:


React native doesn't have any transform origin property yet. maybe in future

so to achieve this 🐈🐈🐈🐈

you should try to use translateX or translateY trick for example to rotate a shape 35 deg from left most

transform: [

            {   
                translateX: -1 * (widthOfShape / 2)

            }
            },

            {
                rotate: '35deg'
            },
            {   
                translateX: (widthOfShape / 2)

            },
        ]

be careful after rotation is done you should translate it back to it's orginal position




回答2:


I have made a lib to achieve transform-origin. react-native-anchor-point

easy to use

import { withAnchorPoint } from 'react-native-anchor-point';

getTransform = () => {
    let transform = {
        transform: [{ perspective: 400 }, { rotateX: rotateValue }],
    };
    return withAnchorPoint(transform, { x: 0, y: 0.5 }, { width: CARD_WIDTH, height: CARD_HEIGHT });
};

<Animated.View style={[styles.blockBlue, this.getTransform()]} />



来源:https://stackoverflow.com/questions/52561376/react-native-transform-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!