`rtl` and `ltr` doesn't work on nativewind4 on native platforms
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 22/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- javascript, react-native, tailwindcss
调研方向
Start with the linked reproduction, specifically src/app/components/EditScreenInfo.tsx, where ltr: and rtl: classes are applied to a Text. Then find where NativeWind resolves direction variants and compare them with I18nManager.isRTL on native. Run the reproduction on a development build, not Expo Go, and check which class wins. Done means ltr:/rtl: apply only when the active direction matches, and the reporter's tw workaround is no longer needed.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
when use ltr: or rtl: in nativewind it should not apply calss unless direction as in prefix, but nativewind run classes without care about them, it apply the last class always as prefix direction is not exist at all
Reproduction
https://github.com/ws-rush/reactive-expo
- above project contain example in src/app/components/EditScreenInfo.tsx:
<Text className="ltr:text-green-500 rtl:text-red-500">{description}</Text>, i tried it also as<Text className="text-green-500 rtl:text-red-500">{description}</Text>and other cominations - the code change direction in
src/app/globals/i18n.ts:
async set(value: string) {
// load and activate locale
const { messages, direction } = this.localesData[value];
i18n.load(value, messages);
i18n.activate(value);
// reload app
if (direction === 'rtl') {
await I18nManager.allowRTL(true);
await I18nManager.forceRTL(true);
} else {
await I18nManager.allowRTL(false);
await I18nManager.forceRTL(false);
}
if ((await locale.loadLocale()) !== value) {
// set app default lang done from app settings
await AsyncStorage.setItem('locale', value);
if (Platform.OS === 'ios' || Platform.OS === 'android') reloadAsync();
else if (Platform.OS === 'web') window.location.reload();
}
},
- finally the app should run in dvelopment build not expo go to get direction changed correctly (get
I18nManager.isRTLcorrect value)
Expected behavior
it should apply classes with direction prefix only if application run in this direction
Additional context
actually original issue is https://github.com/nativewind/nativewind/issues/959 from nativewind 4.0, but problems still exist. I solved this proble currently by add this to my project
import { I18nManager, Platform } from "react-native";
export function tw(strings: TemplateStringsArray, ...values: any[]) {
// Combine the string literals and the values into a single string
let combinedString = strings.reduce((result, string, i) => {
return result + string + (values[i] || '');
}, '');
// Split the combined string into an array of classes
let classes = combinedString.split(' ');
// Filter out classes that start with "rtl:"
let filteredClasses = classes.filter(cls => {
if (Platform.OS !== 'web') return !cls.startsWith(I18nManager.isRTL ? 'ltr:' : 'rtl:')
else return true
});
// Join the filtered classes back into a single string
return filteredClasses.join(' ');
}
then apply it as <Text className={twltr:text-green-500 rtl:text-red-500}>{solved ${description}}</Text>
- 主要语言
- JavaScript
- 星标
- 8.1k
- 派生
- 409
- 平均合并
- 13 小时 16 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nativewind/nativewind 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
nativewind/nativewind#1879 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
nativewind/nativewind#1878 ·
-
`withNativewind(config, { globalClassNamePolyfill: undefined })` turns the className polyfill off可能已有人在做 @EnesKartal 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
nativewind/nativewind#1877 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
nativewind/nativewind#1870 · 5 个 reaction ·
-
printUpgradeWarning crashes the app when serializing props that contain a context object with a throwing getter (e.g. React Navigation)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭needs investigation needs reproduction
难度 2/5 1-3 小时 新手友好度 65/100
nativewind/nativewind#1812 · 5 条评论 ·
查看 nativewind/nativewind 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 65/100
维护者通常 1 天内回复
-
Add toro4n to the data modeling tools可能已有人在做 @henriklantzhedstrom-prog 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 62/100
neo4j/docs-getting-started#546 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 25 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
libnativeapi/nativeapi#21 ·
-
area: core complexity: easy impact: medium
难度 2/5 1-3 小时 新手友好度 86/100
ueberdosis/tiptap#8668 ·
维护者通常 1 天内回复