react-native icon indicating copy to clipboard operation
react-native copied to clipboard

`borderStyle: 'dashed'` and `borderWidth: 1, borderTopWidth: 0` not working on iOS. How else to create a dashed line?

Open a-klotz-p8 opened this issue 6 months ago • 4 comments

Description

When attempting to render a dashed border in React Native using:

borderStyle: 'dashed',
borderWidth: 1,
borderTopWidth: 0,

the style does not render correctly on iOS. This issue can be reproduced using the code provided, where the onlyAndroid style fails to render a dashed border properly on iOS devices. The dashed style disappears.

So how are we supposed to create a clean dashed line in a bare react native project? I feel like this is a pretty basic styling element that should not require any packages (for example using svgs).

Steps to reproduce

  1. open the reproduces provided and choose a iOS device

React Native Version

0.79.0

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.4.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Memory: 599.68 MB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.3.0
    path: /usr/local/bin/node
  Yarn: Not Found
  npm:
    version: 10.9.0
    path: /usr/local/bin/npm
  Watchman:
    version: 2025.03.10.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.4
      - iOS 18.4
      - macOS 15.4
      - tvOS 18.4
      - visionOS 2.4
      - watchOS 11.4
  Android SDK:
    API Levels:
      - "34"
      - "35"
    Build Tools:
      - 32.0.0
      - 33.0.0
      - 34.0.0
      - 35.0.0
    System Images:
      - android-30 | Google Play Intel x86 Atom
      - android-31 | Google APIs Intel x86_64 Atom
      - android-33 | Google Play Intel x86_64 Atom
      - android-34 | Intel x86_64 Atom
      - android-34 | Google APIs Intel x86_64 Atom
      - android-34 | Google Play Intel x86_64 Atom
      - android-35 | ARM 64 v8a
      - android-35 | Intel x86_64 Atom
      - android-35 | Google APIs Intel x86_64 Atom
      - android-35 | Google Play Intel x86_64 Atom
      - android-36 | Pre-Release 16 KB Page Size Google Play Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.22562.218.2431.13114758
  Xcode:
    version: 16.3/16E140
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 3.3.5
    path: /usr/local/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.78.0
    wanted: 0.78.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

No crash or failure

MANDATORY Reproducer

https://snack.expo.dev/@alex_p8/biased-red-french-fries?platform=android

Screenshots and Videos

Android behavior (expected): Image

iOS behavior (issue): Image

a-klotz-p8 avatar May 28 '25 12:05 a-klotz-p8

[!WARNING] Could not parse version: We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.76.2.

react-native-bot avatar May 28 '25 12:05 react-native-bot

[!WARNING] Could not parse version: We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.76.2.

react-native-bot avatar May 28 '25 12:05 react-native-bot

React Native Version

0.79.0

a-klotz-p8 avatar May 28 '25 12:05 a-klotz-p8

In the RCTBorderDrawing file there is a comment that iOS only supports dashed / dotted with a single colour + single width due to that being required and supported by Android. But Android seems to support dashed / dotted with multiple widths currently. So why has this not yet been added to iOS?

a-klotz-p8 avatar May 28 '25 13:05 a-klotz-p8

dashed border is not supported in iOS.

Image

you can try something like this

{Array.from({ length: 4 }).map((_, index) => ( <View key={index} style={[{width: 2, height: 6, backgroundColor: 'green'}, index != 3 && {marginBottom: 4}]} />))}

you can make it either vertical or horizontal dashed line

Yandamuri avatar Oct 17 '25 07:10 Yandamuri