EricPKerr / react-native-emoji

☕Emoji component for React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Svg Text support?

jamidwyer opened this issue · comments

Thank you for sharing this!

We needed to use an emoji inside an SVG and Android was not positioning the emoji correctly.

I think the fix might be something like:

'use strict';

import React, { PureComponent } from 'react';
import { Text } from 'react-native';
import Svg from 'react-native-svg';
import PropTypes from 'prop-types';
import nodeEmoji from 'node-emoji';

const SvgText = Svg.Text;

export default class Emoji extends PureComponent {
  static propTypes = {
    name: PropTypes.string.isRequired,
    svg: PropTypes.bool,
    ...Text.propTypes
  };

  render() {
    const { name, svg, ...props } = this.props;
    const emoji = nodeEmoji.get(name);
    if (!svg) {
      return (<Text {...props}>{ emoji }</Text>);
    }
    return (<SvgText {...props}>{ emoji }</SvgText>);
  }
}

I can submit a PR if you'd like or feel free to make the change if you think it's useful. Thanks again for sharing your work! 🏅