fix: 안드로이드 앱에서 한글이 단어 중간에서 줄바꿈되던 것 (띄어쓰기에서만 줄이 바뀌게)
This commit is contained in:
1 parent
64ca463591
commit
fbebdcb796
21 files changed
+58
-20
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { Children, type ReactNode } from 'react';
|
||||
import { Platform, Text as RNText, type TextProps } from 'react-native';
|
||||
|
||||
const WORD_JOINER = '\u2060';
|
||||
const HANGUL = /[\uAC00-\uD7A3]/;
|
||||
|
||||
/** 안드로이드는 한글을 글자마다 끊어서, 단어 안쪽에 줄바꿈 금지 문자를 넣어 띄어쓰기에서만 줄이 바뀌게 한다 */
|
||||
function keepWords(s: string): string {
|
||||
return HANGUL.test(s) ? s.replace(/\S+/g, (w) => Array.from(w).join(WORD_JOINER)) : s;
|
||||
}
|
||||
|
||||
function wrap(children: ReactNode): ReactNode {
|
||||
return Children.map(children, (c) => (typeof c === 'string' ? keepWords(c) : c));
|
||||
}
|
||||
|
||||
export function Text({ children, ...props }: TextProps) {
|
||||
return <RNText {...props}>{Platform.OS === 'android' ? wrap(children) : children}</RNText>;
|
||||
}
|
||||
Reference in new issue
Block a user