ATProto Browser

ATProto Browser

Experimental browser for the Atmosphere

Post

You can usually structure views to avoid this, and more (but not all) view modifiers now support a toggle for an inert variant. But if you have to, you can avoid type-erasing via `AnyView` by annotating your function with @ViewBuilder and using an explicit `if` statement instead of a ternary

Dec 18, 2024, 10:45 AM

Record data

{
  "uri": "at://did:plc:3ywuhhs7edzwa4j3eaqyte4l/app.bsky.feed.post/3ldl6hyqmis27",
  "cid": "bafyreigcgalyr6k3dhaz5hvwcypm45tymxeohr745go4cywiijfcrxhebi",
  "value": {
    "text": "You can usually structure views to avoid this, and more (but not all) view modifiers now support a toggle for an inert variant. But if you have to, you can avoid type-erasing via `AnyView` by annotating your function with @ViewBuilder and using an explicit `if` statement instead of a ternary",
    "$type": "app.bsky.feed.post",
    "embed": {
      "$type": "app.bsky.embed.images",
      "images": [
        {
          "alt": "extension View {\n    @ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {\n        if condition {\n            transform(self)\n        } else {\n            self\n        }\n    }\n}",
          "image": {
            "$type": "blob",
            "ref": {
              "$link": "bafkreidrviwcawssgyi4ozzmdan5zw5vqj47i7q2cuezgvji5phnrmtpeu"
            },
            "mimeType": "image/jpeg",
            "size": 104705
          },
          "aspectRatio": {
            "width": 1590,
            "height": 324
          }
        }
      ]
    },
    "langs": [
      "en"
    ],
    "reply": {
      "root": {
        "cid": "bafyreih33dek3i7usrqwvvfbs3kq6abywv337hg2xnopxasdiqccu7aq2e",
        "uri": "at://did:plc:3ul5ulg5pnkqw7bnnsowjnrr/app.bsky.feed.post/3ldimeh4ohs27"
      },
      "parent": {
        "cid": "bafyreigequxzgkmewyjkjlyxfa5eutifh2kglkg27w57ed5y2tpy4jbzaa",
        "uri": "at://did:plc:3ul5ulg5pnkqw7bnnsowjnrr/app.bsky.feed.post/3ldkzpo3rwc2m"
      }
    },
    "createdAt": "2024-12-18T10:45:15.926Z"
  }
}