Slide 1

Slide 1 text

Exit 8 for SwiftUI ojun - DeNA co., Ltd. try! Swift Tokyo 2025 LT 2025 / 04 / 11

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Exit 1 Prevent double taps or simultaneous taps

Slide 4

Slide 4 text

Exit 1 Prevent double taps or simultaneous taps Two buttons inside a VStack

Slide 5

Slide 5 text

Exit 1 Prevent double taps or simultaneous taps In this case, we need to prevent multiple buttons from being tapped simultaneously. However, SwiftUI doesn’t provide a direct API to handle mutual exclusion between buttons.

Slide 6

Slide 6 text

Exit 1 Prevent double taps or simultaneous taps Set isExclusiveTouch to false on the wrapped UIView and all of its child views. If needed, implement a custom gesture recognizer to handle touch exclusivity.

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Exit 2 Match the line height to the Text

Slide 9

Slide 9 text

Exit 2 Match the line height to the Text Inside the ZStack, there's a Color and an HStack. The HStack contains a Rectangle and a titleView.

Slide 10

Slide 10 text

Exit 2 Match the line height to the Text This UI is similar to what you might see in a train schedule display.

Slide 11

Slide 11 text

Exit 2 Match the line height to the Text This UI is similar to what you might see in a train schedule display. However, you can see that the orange line doesn't match the height of the Text.

Slide 12

Slide 12 text

Exit 2 Match the line height to the Text By creating a structure that conforms to the Layout protocol, you can align their heights.

Slide 13

Slide 13 text

Exit 2 Match the line height to the Text Applying this layout to the original code allows the orange line to match the height of the Text.

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Exit 3 Customize the loading indicator

Slide 16

Slide 16 text

Exit 3 Customize the loading indicator

Slide 17

Slide 17 text

Exit 3 Customize the loading indicator Since customization isn't possible in SwiftUI, we need to implement it using UIKit.

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Exit 4 Dismiss the keyboard on scroll

Slide 20

Slide 20 text

Exit 4 Dismiss the keyboard on scroll This behavior is supported on iOS 16 and later. The keyboard automatically hides when the user scrolls, which simpli fi es the design.

Slide 21

Slide 21 text

Exit 4 Dismiss the keyboard on scroll By using scrollDismissesKeyboard, we can implement this in a much simpler way.

Slide 22

Slide 22 text

Exit 5 Presenting a share sheet

Slide 23

Slide 23 text

Exit 5 Presenting a share sheet This code works on iOS 16 and later. We're currently using UIActivityViewController to show the Share Sheet.

Slide 24

Slide 24 text

Exit 5 Presenting a share sheet By switching to ShareLink, we can eliminate the dependency on UIKit.

Slide 25

Slide 25 text

Exit 6 Empty data state

Slide 26

Slide 26 text

Exit 6 Empty data state

Slide 27

Slide 27 text

Exit 6 Empty data state

Slide 28

Slide 28 text

Exit 7 Mesh gradient expression

Slide 29

Slide 29 text

Exit 7 Mesh gradient expression

Slide 30

Slide 30 text

Exit 7 Mesh gradient expression Starting from iOS 18, MeshGradient makes it easy to implement mesh gradients.

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Exit 8 Square Without GeometryReader

Slide 33

Slide 33 text

Exit 8 Square Without GeometryReader

Slide 34

Slide 34 text

Exit 8 Square Without GeometryReader It's possible to create a square without using GeometryReader by leveraging scaledToFit.

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content