Slide 1

Slide 1 text

Road to Single Activity

Slide 2

Slide 2 text

About me yurihondo Software Engineer@U-NEXT Moving in with the in-laws next month - wish me luck! X : yurihondo @yuyuyuyuyuri

Slide 3

Slide 3 text

Motivation When overhauling the screen transition mechanism with Navigation Compose, we gained some serious pain knowledge. Sharing it.

Slide 4

Slide 4 text

Covered Topics ● Gradual Migration from AndroidView to Compose Using Navigation ● Examples of Using Navigation in Apps with Complex Screen Transitions

Slide 5

Slide 5 text

NOT Covered Topics ● Basics of Navigation Setup and More ● Knowledge for Migrating Layouts to Compose

Slide 6

Slide 6 text

Environment Compose: 1.6.X Navigation: 2.7.7

Slide 7

Slide 7 text

Environment Compose: 1.6.X Navigation: 2.7.7

Slide 8

Slide 8 text

Screen Transition Sample Navigation 2.7.7 https://github.com/yurihondo/screentransitionsample Navigation 2.8.x https://github.com/yurihondo/screentransitionsample/tree/feature/navigation_v2.8.x Compose Destinations https://github.com/yurihondo/screentransitionsample/tree/feature/compose_destinations

Slide 9

Slide 9 text

Agenda ● Background ● Good-bye Fragment ● Hello Single Activity

Slide 10

Slide 10 text

Background

Slide 11

Slide 11 text

Background ● About U-NEXT app ● Migrations

Slide 12

Slide 12 text

Background ● About U-NEXT app ● Migrations

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Large Screens

Slide 16

Slide 16 text

Common Screens

Slide 17

Slide 17 text

Deep Links Dummy Title ストーリー. ダミーストーリー。ダミーストーリー。 ... Intent

Slide 18

Slide 18 text

U-NEXT app for Android ■ Large Screens ■ Common Screens ■ Deep Links

Slide 19

Slide 19 text

Background ● About U-NEXT app ● Migrations

Slide 20

Slide 20 text

Activity Activity Activity Framgent Fragment Transaction

Slide 21

Slide 21 text

Main Activity Common Screen (Activity) Activity Activity Activity

Slide 22

Slide 22 text

Fragment Compose

Slide 23

Slide 23 text

Activity Activity Activity Nav Graph Navigation Screen (Compose)

Slide 24

Slide 24 text

Single Activity Nav Graph Navigation Screen (Compose)

Slide 25

Slide 25 text

The cost of multiple Activities 1. Common Settings: Cost of setting things like CompositionLocal across all Activities 2. NavHost: Cost of implementing NavHost for each Activity

Slide 26

Slide 26 text

The cost of multiple Activities 1. Common Settings: Cost of setting things like CompositionLocal across all Activities 2. NavHost: Cost of implementing NavHost for each Activity Improve app maintainability and scalability

Slide 27

Slide 27 text

Migration Step1: Abolish Fragments and migrate the app to Full-Navigation Step2: Switch to a Single Activity architecture

Slide 28

Slide 28 text

Good-bye Fragment

Slide 29

Slide 29 text

Legacy screen transition mechanism

Slide 30

Slide 30 text

Activity Container (Fragment) Screen Screen Screen (Fragment) Screen (Composable)

Slide 31

Slide 31 text

Activity Container (Fragment) Screen Screen Screen (Fragment) Screen (Composable)

Slide 32

Slide 32 text

Video Container (Fragment) Book Container (Fragment) Search Container (Fragment)

Slide 33

Slide 33 text

Screen Screen Activity Container (Fragment) Screen (Fragment) Screen (Composable)

Slide 34

Slide 34 text

Search Container (Fragment) Video Container (Fragment) Book Container (Fragment) Activity hide show ・・・ hide

Slide 35

Slide 35 text

Screen Screen Activity Container (Fragment) Screen (Fragment) Screen (Composable)

Slide 36

Slide 36 text

NavGraph Activity Screen (Composable) Nested NavGraph

Slide 37

Slide 37 text

NavGraph Activity Screen (Composable) Nested NavGraph Proceed in phases 1. Convert screens to Composables, then create and integrate them into the NavGraph 2. Integration of the created NavGraphs.

Slide 38

Slide 38 text

Good-bye Fragment Phase 1: Graphs by Feature Phase 2-1: Graph Integration Phase 2-2: Adapting to App Specifics

Slide 39

Slide 39 text

Good-bye Fragment Phase 1: Graphs by Feature Phase 2-1: Graph Integration Phase 2-2: Adapting to App Specifics

Slide 40

Slide 40 text

Screen Screen Activity Container (Fragment) Screen (Fragment) Screen (Composable) Activity Screen (Composable) NavGraph Container (Fragment) Phase 1

Slide 41

Slide 41 text

Screen Screen Activity Container (Fragment) Screen (Fragment) Screen (Composable)

Slide 42

Slide 42 text

Container (Fragment) Container (Fragment) Graph Screen (Composable) Graph Screen (Composable) Feature Feature

Slide 43

Slide 43 text

Screen Conversion 1 2 3 Add to NavHost NavGraph Setup

Slide 44

Slide 44 text

NavGraph Setup Screen Conversion 1 2 3 Add to NavHost

Slide 45

Slide 45 text

Fragments using XML layouts will migrate to Compose UI...

Slide 46

Slide 46 text

Add to NavHost NavGraph Setup Screen Conversion 1 2 3

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Container (Fragment) Container (Fragment) Graph Screen (Composable) Graph Screen (Composable) Common Screen

Slide 52

Slide 52 text

Container (Fragment) Container (Fragment) Graph Screen (Composable) Graph Screen (Composable) Common Screen Common Graph

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Can be added as a NavGraph destination, but can't navigate back to the original NavHost's destination from the target Activity.

Slide 55

Slide 55 text

Add to NavHost NavGraph Setup Screen Conversion 1 2 3

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

NavGraphへ 集約 NavGraph 作成 Screen Compose化 1 2 3 Completed Compose Conversion and NavGraph Definition for All Screens

Slide 60

Slide 60 text

Activity Screen (Composable) NavGraph Container (Fragment)

Slide 61

Slide 61 text

Good-bye Fragment Phase 1: Graphs by Feature Phase 2-1: Graph Integration Phase 2-2: Adapting to App Specifics

Slide 62

Slide 62 text

NavGraph Activity Screen (Composable) Nested NavGraph Activity Screen (Composable) NavGraph Container (Fragment) Phase 2

Slide 63

Slide 63 text

Activity MainGraph Video Graph Book Graph Search Graph ・・・

Slide 64

Slide 64 text

Safely Continue Feature Development During Refactoring Feature development Refactoring

Slide 65

Slide 65 text

New Root Debug menu OLD Root

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Switching core UI invocation processes using mechanisms like Feature Flags

Slide 68

Slide 68 text

New Root OLD Root

Slide 69

Slide 69 text

Long-term migration work is feasible Refactoring Feature development

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

NavGraph Activity Screen (Composable) Nested NavGraph

Slide 72

Slide 72 text

Good-bye Fragment Phase 1: Graphs by Feature Phase 2-1: Graph Integration Phase 2-2: Adapting to App Specifics

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

❶ ❷ ❸ Back

Slide 75

Slide 75 text

❶ ❷ ❸ ❹ Back Back

Slide 76

Slide 76 text

❶ ❷ ❸ ❹

Slide 77

Slide 77 text

Video Graph Book Graph Search Graph Library Graph ❶ ❷

Slide 78

Slide 78 text

Video Graph Book Graph Search Graph Library Graph ❶ ❷ ● Tab-Graph Mapping ● Graph Switching Process

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

❶ ❷ ❸ ❹ Back Back

Slide 89

Slide 89 text

BookGraph BackStackEntry BackStackEntry SearchGraph BackStackEntry BackStackEntry Back

Slide 90

Slide 90 text

BookGraph BackStackEntry BackStackEntry SearchGraph BackStackEntry BackStackEntry

Slide 91

Slide 91 text

BookGraph BackStackEntry BackStackEntry SearchGraph BackStackEntry

Slide 92

Slide 92 text

BookGraph BackStackEntry BackStackEntry SearchGraph BackStackEntry ● Controlling Back Events ● Managing Tab Selection History

Slide 93

Slide 93 text

Reference link

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

https://issuetracker.google.com/issues/308445371 Calling BackHandler before NavHost gets overridden by NavHost.

Slide 96

Slide 96 text

If BackStackEntry is the StartRoute of a Graph, it should navigate to the previous Tab (Graph).

Slide 97

Slide 97 text

Building a System to Manage Tab Selection History

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

BookGraph BackStackEntry BackStackEntry SearchGraph BackStackEntry BackStackEntry navigate pop

Slide 105

Slide 105 text

Full-Compose + Full-Navigation

Slide 106

Slide 106 text

Hello Single Activity

Slide 107

Slide 107 text

Core Essentials: ● Screen Reassignment ● Backing Result Update

Slide 108

Slide 108 text

Core Essentials: ● Screen Reassignment ● Backing Result Update

Slide 109

Slide 109 text

MainActivity XxxActivity MainGraph NestedGraph Graph Composable

Slide 110

Slide 110 text

MainActivity XxxActivity MainGraph NestedGraph Graph Composable

Slide 111

Slide 111 text

Core Essentials: ● Screen Reassignment ● Backing Result Update

Slide 112

Slide 112 text

Activity Composable Result Composable

Slide 113

Slide 113 text

Composable Result Composable

Slide 114

Slide 114 text

Composable Result Composable

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

Additional Essentials: ● Controlling Tab Visibility ● DeepLinks

Slide 117

Slide 117 text

Additional Essentials: ● Controlling Tab Visibility ● DeepLinks

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

Tab visibility behavior: 1. Hide 2. Same As Parent

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

Won't the display break when returning to a SAME_AS_PARENT Destination...?

Slide 129

Slide 129 text

HIDE SAME AS PARENT SHOW Parent

Slide 130

Slide 130 text

HIDE SAME AS PARENT SHOW Parent

Slide 131

Slide 131 text

HIDE SAME AS PARENT SHOW Parent

Slide 132

Slide 132 text

HIDE SAME AS PARENT SHOW Parent ● Detecting Back Navigation ● Restoring Tab visibility

Slide 133

Slide 133 text

currentBackStackを ハックする

Slide 134

Slide 134 text

https://github.com/yurihondo/screentransitionsample

Slide 135

Slide 135 text

Screen B currentBackStack Screen A Screen B Screen C Parent

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

Additional Essentials: ● Controlling Tab Visibility ● DeepLinks

Slide 139

Slide 139 text

Dummy Title ストーリー. ダミーストーリー。ダミーストーリー。 ... Intent

Slide 140

Slide 140 text

Screen (Activity) DeepLinks Activity TaskStack Builder WEB Intent Screen (Activity) Intent Intent

Slide 141

Slide 141 text

Controlling the BackStack is challenging...

Slide 142

Slide 142 text

MainActivity DeepLinks Activity TaskStack Builder WEB Intent Intent MainGraph Navigate

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

Single Activity

Slide 148

Slide 148 text

Conclusion

Slide 149

Slide 149 text

Effect of the Work ● Reduced workload and issues related to adding new screens ● Deeper understanding of Navigation implementation Lessons Learned ● The challenge of balancing Navigation principles with custom UX ● Tailoring Navigation to better fit our environment

Slide 150

Slide 150 text

Screen Transition Sample Navigation 2.7.7 https://github.com/yurihondo/screentransitionsample Navigation 2.8.x https://github.com/yurihondo/screentransitionsample/tree/feature/navigation_v2.8.x Compose Destinations https://github.com/yurihondo/screentransitionsample/tree/feature/compose_destinations

Slide 151

Slide 151 text

Thanks