viro icon indicating copy to clipboard operation
viro copied to clipboard

ViroText cannot render Korean

Open HERO-ILATI opened this issue 5 years ago • 10 comments

Environment

  1. Development OS: Mac, iOS
  2. Device OS & Version: iPhoneXS / iOS 12
  3. Version: ViroReact : 2.13.0 / React Native : 0.57.7

Description

https://github.com/viromedia/viro/issues/186

I found that ViroText support Korean since ViroReact v2.5.1 but it still cannot render Korean like this. I used system font and NotoSansCJK and some others. what fonts are used for testing Korean or Japanese? I'm gonna test that one. Thank you.

test

HERO-ILATI avatar Mar 26 '19 16:03 HERO-ILATI

Same issue

Development OS: MacOS Device OS & Version: Sansung s8 / Android 8 Version: ViroReact : 2.13.0 / React Native : 0.57.7

ajaxsys avatar Apr 10 '19 12:04 ajaxsys

and also

Development OS: MacOS Device OS & Version: Sansung s8 / Android 9 Version: ViroReact : 2.14.0 / React Native : 0.59

ajaxsys avatar Apr 24 '19 07:04 ajaxsys

For iOS you should use "PingFang HK" to render Korean, and for Android "NotoSansCJK". Note that not all Android devices have the "NotoSansCJK" font installed.

radvani avatar Jun 26 '19 15:06 radvani

For IOS, You can use "Apple SD Gothic Neo" to render Korean

geotwo-JinsolLee avatar Sep 07 '21 02:09 geotwo-JinsolLee

I spent a lot of time on this problem, but I solved it.

import React, { useEffect, useRef, useState } from "react";
import { ViroText, ViroTextStyle } from "@viro-community/react-viro";
import { ColorValue } from "react-native";

export type ViroCustomTextProps = {
  text: string;
  color?: ColorValue;
  extrusionDepth?: number;
  style?: ViroTextStyle;
  outerStroke?: {
    type?: "None" | "Outline" | "DropShadow";
    width?: number;
    color?: ColorValue;
  };
  maxLines?: number;
  textClipMode?: "None" | "ClipToBounds";
  textLineBreakMode?: "WordWrap" | "CharWrap" | "Justify" | "None";
  width?: number;
  height?: number;
};

export function ViroCustomText(props: ViroCustomTextProps) {
  const {
    text,
    color,
    extrusionDepth,
    maxLines,
    outerStroke,
    style,
    textClipMode,
    textLineBreakMode,
    width,
    height,
  } = props;

  const ref = useRef<ViroText>();
  const [render, setRender] = useState(false);

  useEffect(() => {
    if (Platform.OS === "android") {
      ref.current.setNativeProps({
        fontFamily: ["SamsungKorean", "NotoSansCJK", "Roboto"].join(","),
      } as any);
    }

    setRender(true);
  }, []);

  return (
    <ViroText
      ref={ref}
      text={!render ? "" : text} // check load font
    />
  );
}

usage

<ViroCustomText 
    text="헤이 모두들 안녕. hello world everybody, 123456789"
/>

ziponia avatar Nov 15 '22 15:11 ziponia