Skip to content

Commit

Permalink
fix(hippy-react): text nest
Browse files Browse the repository at this point in the history
  • Loading branch information
tsangint authored and xuqingkuang committed Mar 17, 2020
1 parent 48258d4 commit da5ca3b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/hippy-react/src/components/text.tsx
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import Style from '@localTypes/style';
import { LayoutableProps, ClickableProps } from '../types';
import { warn, unicodeToChar } from '../utils';
import { unicodeToChar } from '../utils';

interface TextProps extends LayoutableProps, ClickableProps {
/**
Expand Down Expand Up @@ -66,12 +66,6 @@ function Text({ style, ...nativeProps }: TextProps) {
}
}

if (process.env.NODE_ENV !== 'production') {
if (typeof nativeProps.children !== 'string' && typeof nativeProps.children !== 'number') {
warn('The children of Text component only suppport string type', nativeProps);
}
}

nativeProps.text = ''; // Important: Text must recevie text props.
if (typeof nativeProps.children === 'string') {
nativeProps.text = unicodeToChar(nativeProps.children);
Expand All @@ -81,8 +75,11 @@ function Text({ style, ...nativeProps }: TextProps) {
const text = nativeProps.children
.filter(t => typeof t === 'string' || typeof t === 'number')
.join('');
nativeProps.text = unicodeToChar(text);
nativeProps.children = nativeProps.text;
// FIXME: if Text is nested, all child components of this component need to be wrapped by Text
if (text) {
nativeProps.text = unicodeToChar(text);
nativeProps.children = nativeProps.text;
}
}

return (
Expand Down

0 comments on commit da5ca3b

Please sign in to comment.