question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transform <G> with setNativeProps possible?

See original GitHub issue

I need to move and scale individual<G> elements with setNativeProps. Nothing I’ve tried seems to work.

I tried:

setNativeProps({x: newX, y: newY})

setNativeProps({x: newX.toString(), y: newY.toString()})

setNativeProps({transform: [{translateX: newX}, {translateY: newY}])

If I use setNativeProps directly on a <Circle> for example, everything works fine.

  • Does G implement setNativeProps?
  • What syntax should I use for setting scale and position on a group?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
msandcommented, Dec 27, 2017

@msageryd You probably need to use something like: setNativeProps({ matrix: [scaleX, skewY, skewX, scaleY, translateX, translateY] })

0reactions
msandcommented, Feb 24, 2020

https://snack.expo.io/@msand/shallow-celery

import React, { Component } from 'react';
import { StyleSheet, View, Animated } from 'react-native';
import { Svg, Circle, G } from 'react-native-svg';

const AnimatedCircle = Animated.createAnimatedComponent(Circle);

function getInitialState() {
  const anim = new Animated.Value(0);
  const fillOpacity = anim.interpolate({
    inputRange: [0, 1],
    outputRange: [0, 1],
  });
  const offset = anim.interpolate({
    inputRange: [0, 1],
    outputRange: [0, 10],
  });
  const strokeOpacity = anim.interpolate({
    inputRange: [0, 0.9],
    outputRange: [0, 1],
    extrapolateRight: 'clamp',
  });
  const strokeWidth = anim.interpolate({
    inputRange: [0, 1],
    outputRange: ['0', '5'],
  });
  return { anim, fillOpacity, offset, strokeOpacity, strokeWidth };
}

export default class App extends Component {
  state = getInitialState();

  componentDidMount() {
    const { anim } = this.state;
    Animated.timing(anim, {
      toValue: 1,
      duration: 3000,
      useNativeDriver: true,
    }).start();
  }

  render() {
    const { fillOpacity, offset, strokeOpacity, strokeWidth } = this.state;
    return (
      <View style={styles.container}>
        <Svg width="100%" height="100%" viewBox="0 0 100 100">
          <G>
            <AnimatedCircle
              cx="50"
              cy="50"
              r="45"
              height="90"
              stroke="blue"
              fill="green"
              strokeDasharray="1 1"
              strokeWidth={strokeWidth}
              strokeDashoffset={offset}
              strokeOpacity={strokeOpacity}
              fillOpacity={fillOpacity}
            />
          </G>
        </Svg>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: '#ecf0f1',
    flex: 1,
  },
});

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transform <G> with setNativeProps possible? #556 - GitHub
I need to move and scale individual elements with setNativeProps. Nothing I've tried seems to work. I tried: setNativeProps({x: newX, ...
Read more >
Transform <G> with setNativeProps possible with react-native ...
I'm now on an FPS-hunt.. Would it be better (or even possible) to set the Svg viewbox via setNativeProps? I.e. would it be...
Read more >
Direct Manipulation - React Native
setNativeProps is imperative and stores state in the native layer (DOM, UIView, etc.) and not within your React components, which makes your ...
Read more >
Navigate to a new page after Onbording with React-Native ...
Transform <G> with setNativeProps possible with react-native-svg? ... How can I pass a props from component A to C while has a B...
Read more >
4. Components for Mobile - Learning React Native, 2nd ...
You'll likely want to create styled components as a sort of shorthand ... This in turn makes it easier to maintain the styling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found