Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for customization of the preview name #478

Merged
merged 2 commits into from
Feb 21, 2024
Merged

Conversation

nsillik
Copy link
Contributor

@nsillik nsillik commented Feb 7, 2024

Before, there was no way to explicitly set preview name, leading to things like this in the Xcode canvas view:

image

With no way to make it look prettier.

With this change we either use the Xcode SwiftUI Previews default, or just the name:

image

now shows:

image

much better!

@nsillik nsillik requested a review from a team as a code owner February 7, 2024 17:47
@@ -67,6 +67,7 @@ public struct ElementPreview: View {
public typealias ElementProvider = () -> Element

private let name: String
private let previewName: String?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is only used for previews—I think we might want to just remove the prefix when using name.

I think we just want an optional previewName override on the Market side.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, here's the result of that suggestion:
image

@kyleve do you have opinions? is keeping the prefix - name worthwhile in any cases?

return ""
}
}()
let formattedName: String? = name.isEmpty ? nil : name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually sure, and fine keeping this in, but should we just allow empty string here? We could document that it maps to .previewDisplayName() so consumers know it matches that behavior.
What happens if you do provide empty string?

Copy link
Contributor Author

@nsillik nsillik Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you pass in an empty string you get the SwiftUI default, if you pass in a name it shows the name. I could have made this trinary (String?) and have nil give you the swiftUI default, empty string keep the same behavior ("size that fits" etc.), and a non-empty string override the preview name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I kinda like the idea of having the name match the type of previewDisplayName but probably not worth the churn. Fine keeping as is!

@nsillik
Copy link
Contributor Author

nsillik commented Feb 7, 2024

  • changelog this

@nsillik nsillik enabled auto-merge (squash) February 21, 2024 14:32
@nsillik nsillik merged commit e27debd into main Feb 21, 2024
5 checks passed
@nsillik nsillik deleted the @nsillik/previewName branch February 21, 2024 14:39
kyleve added a commit that referenced this pull request Mar 16, 2024
…ller

* origin/main: (62 commits)
  AccessibilityBlocker aggressively blocking. (#483)
  Bumping version to 3.0.0 (#482)
  Allow for customization of the preview name (#478)
  Update CHANGELOG for AttributedLabel fixes (#480)
  Fix link detection for stretched labels (#476)
  chore: Updated minimum deployment target from iOS 14 to iOS 15 [UI-5185] (#479)
  chore(ios): Bump to Xcode 15.1 and Ruby 3.2.2 [UI-5184] (#477)
  AXCustomContent Support (#471)
  Bumping versions to 2.2.0 (#470)
  Update concatenation logic and unit tests
  update changelog
  never cache subelements
  optionally do not cache subelements
  Feature: add TintAdjustmentMode, modifiers, and tests
  Add to CHANGELOG
  Add tintAdjustmentMode to Image
  Bumping versions to 2.1.0 (#466)
  Resolved a Swift 5.9 compilation warning (#465)
  Update KeyboardObserver (#463)
  Bump activesupport from 7.0.4.3 to 7.0.7.2
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants