react / react/react-native

[0.73.1] fontWeight not apply while using custom font

Đang mở
#42,116 17 bình luận 3 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Issue: Author Provided Repro
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

Description

I just tried to use custom font in my project template, and i realize when i want to use fontWeight as a reference of my custom font family it's not applicable, is it expected or am i doing something wrong while linking my custom font?

I'm expecting fontWeight should applicable with font as google fonts declared

  1. Thin 100
  2. Thin 100 Italic
  3. ExtraLight 200
  4. ...
Screen Shot 2024-01-02 at 00 08 25
Steps to reproduce
  1. Download font from google
  2. Extract downloaded font and copy font into project directory (without pt prefix)
  3. linking the fonts with react-native-asset
  4. Paste this code in App.[js/tsx]
import React from 'react';
import { Text, View } from 'react-native';

const TextExample = props => {
  const fontListRegularWithFontWeight = [
    {fontFamily: 'DMSans-Regular', fontWeight: '100'},
    {fontFamily: 'DMSans-Regular', fontWeight: '200'},
    {fontFamily: 'DMSans-Regular', fontWeight: '300'},
    {fontFamily: 'DMSans-Regular', fontWeight: '400'},
    {fontFamily: 'DMSans-Regular', fontWeight: '500'},
    {fontFamily: 'DMSans-Regular', fontWeight: '600'},
    {fontFamily: 'DMSans-Regular', fontWeight: '700'},
    {fontFamily: 'DMSans-Regular', fontWeight: '800'},
    {fontFamily: 'DMSans-Regular', fontWeight: '900'},
  ];

  const fontListWithCustomFontOnly = [
    {fontFamily: 'DMSans-Thin'},
    {fontFamily: 'DMSans-ExtraLight'},
    {fontFamily: 'DMSans-Light'},
    {fontFamily: 'DMSans-Regular'},
    {fontFamily: 'DMSans-Medium'},
    {fontFamily: 'DMSans-SemiBold'},
    {fontFamily: 'DMSans-Bold'},
    {fontFamily: 'DMSans-ExtraBold'},
    {fontFamily: 'DMSans-Black'},
  ];

  return (
    <View style={{flex: 1}}>
      <Text style={{textAlign: 'center'}}>Custom Font Regular with fontWeight</Text>
      <View style={{borderWidth: 1, margin: 14, padding: 14, marginBottom: 24, alignItems: 'center'}}>
        {fontListRegularWithFontWeight.map((x, i) => (
          <Text key={x.fontFamily + i} style={x}>
            {JSON.stringify(x)}
          </Text>
        ))}
      </View>

      <Text style={{textAlign: 'center'}}>Custom Font With Exact Font Name</Text>
      <View style={{borderWidth: 1, margin: 14, padding: 14, alignItems: 'center'}}>
        {fontListWithCustomFontOnly.map((x, i) => (
          <Text key={x.fontFamily + i} style={x}>
            {JSON.stringify(x)}
          </Text>
        ))}
      </View>
    </View>
  );
};

export default TextExample;
React Native Version

0.73.1

Affected Platforms

Runtime - Android

Output of npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 12.5
  CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Memory: 679.42 MB / 16.00 GB
  Shell:
    version: 5.8.1
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.yarn/bin/yarn
  npm:
    version: 10.2.3
    path: /usr/local/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 21.4
      - iOS 16.0
      - macOS 12.3
      - tvOS 16.0
      - watchOS 9.0
  Android SDK:
    API Levels:
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 29.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
    System Images:
      - android-23 | Intel x86 Atom_64
      - android-27 | Google APIs ARM 64 v8a
      - android-28 | Google APIs Intel x86 Atom
      - android-29 | Google APIs Intel x86 Atom
      - android-30 | Google APIs Intel x86 Atom
      - android-30 | Google Play ARM 64 v8a
      - android-34 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10406996
  Xcode:
    version: 14.0.1/14A400
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 2.7.4
    path: /Users/administrator_1/.rvm/rubies/ruby-2.7.4/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.1
    wanted: 0.73.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false


### Stacktrace or Logs

```text
noneed
Reproducer

https://snack.expo.dev/w667bnl74

Screenshots and Videos
Screen Shot 2024-01-02 at 00 14 50

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với Snack được liên kết và bản tái hiện App.[js/tsx] trên Android 0.73.1, kiểm tra hai mảng fontFamily/fontWeight và các asset DM Sans được liên kết. So sánh các weight quan sát được với các ánh xạ 100–900 dự kiến; công việc được xem là hoàn tất khi xác định được đây là lỗi của React Native Android hay vấn đề về liên kết hoặc sử dụng font, đồng thời ghi lại bản sửa cần thiết hoặc hướng dẫn tương ứng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, javascript, react-native
Lĩnh vực
mobile
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.