@@ -4,11 +4,14 @@ import android.content.res.Configuration
4
4
import androidx.compose.foundation.layout.Arrangement
5
5
import androidx.compose.foundation.layout.Box
6
6
import androidx.compose.foundation.layout.Column
7
+ import androidx.compose.foundation.layout.Row
7
8
import androidx.compose.foundation.layout.Spacer
8
9
import androidx.compose.foundation.layout.WindowInsets
9
10
import androidx.compose.foundation.layout.fillMaxHeight
10
11
import androidx.compose.foundation.layout.fillMaxWidth
12
+ import androidx.compose.foundation.layout.height
11
13
import androidx.compose.foundation.layout.padding
14
+ import androidx.compose.foundation.layout.sizeIn
12
15
import androidx.compose.material3.FabPosition
13
16
import androidx.compose.material3.LocalTextStyle
14
17
import androidx.compose.material3.MaterialTheme
@@ -18,9 +21,11 @@ import androidx.compose.material3.Text
18
21
import androidx.compose.material3.contentColorFor
19
22
import androidx.compose.runtime.Composable
20
23
import androidx.compose.runtime.CompositionLocalProvider
24
+ import androidx.compose.runtime.remember
21
25
import androidx.compose.ui.Alignment
22
26
import androidx.compose.ui.Modifier
23
27
import androidx.compose.ui.graphics.Color
28
+ import androidx.compose.ui.platform.LocalConfiguration
24
29
import androidx.compose.ui.text.style.TextAlign
25
30
import androidx.compose.ui.tooling.preview.Preview
26
31
import androidx.compose.ui.unit.dp
@@ -40,6 +45,7 @@ fun PinScaffold(
40
45
contentWindowInsets : WindowInsets = ScaffoldDefaults .contentWindowInsets,
41
46
description : (@Composable () -> Unit )? = null,
42
47
error : Boolean = false,
48
+ useSmallButtons : Boolean = false,
43
49
codeLength : Int ,
44
50
) {
45
51
Scaffold (
@@ -53,44 +59,116 @@ fun PinScaffold(
53
59
contentColor = contentColor,
54
60
contentWindowInsets = contentWindowInsets,
55
61
) {
56
- Column (
57
- modifier = Modifier
58
- .fillMaxWidth()
59
- .fillMaxHeight()
60
- .padding(it)
61
- .padding(40 .dp)
62
- .padding(bottom = 16 .dp),
63
- verticalArrangement = Arrangement .spacedBy(16 .dp, Alignment .Bottom ),
64
- horizontalAlignment = Alignment .CenterHorizontally
65
- ) {
66
- if (description != null ) {
67
- Spacer (modifier = Modifier .weight(1f ))
62
+ val orientation = LocalConfiguration .current.orientation
63
+ val minButtonSize = remember(useSmallButtons) {
64
+ if (useSmallButtons) {
65
+ PinButtonDefaults .PinButtonSmallMinSize
66
+ } else {
67
+ PinButtonDefaults .PinButtonNormalMinSize
68
+ }
69
+ }
70
+ if (orientation == Configuration .ORIENTATION_LANDSCAPE ) {
71
+ Row (
72
+ modifier = Modifier
73
+ .fillMaxWidth()
74
+ .fillMaxHeight()
75
+ .padding(it)
76
+ .padding(horizontal = 20 .dp),
77
+ horizontalArrangement = Arrangement .SpaceAround ,
78
+ verticalAlignment = Alignment .CenterVertically
79
+ ) {
68
80
Box (
69
- modifier = Modifier .fillMaxWidth(),
70
- contentAlignment = Alignment .Center
81
+ modifier = Modifier
82
+ .fillMaxWidth(0.5f )
83
+ .fillMaxHeight()
71
84
) {
72
- CompositionLocalProvider (
73
- LocalTextStyle provides MaterialTheme .typography.headlineMedium.copy(
74
- textAlign = TextAlign .Center
75
- )
85
+ Column (
86
+ modifier = Modifier .fillMaxHeight(),
87
+ verticalArrangement = Arrangement .Center ,
88
+ horizontalAlignment = Alignment . CenterHorizontally
76
89
) {
77
- description()
90
+ if (description != null ) {
91
+ Box (
92
+ modifier = Modifier .fillMaxWidth(),
93
+ contentAlignment = Alignment .Center
94
+ ) {
95
+ CompositionLocalProvider (
96
+ LocalTextStyle provides MaterialTheme .typography.headlineMedium.copy(
97
+ textAlign = TextAlign .Center
98
+ )
99
+ ) {
100
+ description()
101
+ }
102
+ }
103
+ Spacer (modifier = Modifier .height(32 .dp))
104
+ }
105
+ PinDisplay (
106
+ modifier = Modifier
107
+ .fillMaxWidth(0.5f ),
108
+ length = codeLength,
109
+ error = error,
110
+ )
78
111
}
79
112
}
80
- Spacer (modifier = Modifier .weight(1f ))
113
+ val pinBoardHorizontalPadding = 16 .dp
114
+ val horizontalButtonSpace = 16 .dp
115
+ val totalPadding = (pinBoardHorizontalPadding * 2 ) + (horizontalButtonSpace * 2 )
116
+ val maxBoxWidth = remember(minButtonSize) {
117
+ val buttonsInRow = 3
118
+ (minButtonSize * buttonsInRow) + totalPadding
119
+ }
120
+ Box (
121
+ modifier = Modifier .sizeIn(maxWidth = maxBoxWidth),
122
+ contentAlignment = Alignment .Center
123
+ ) {
124
+ PinBoard (
125
+ modifier = Modifier .padding(horizontal = pinBoardHorizontalPadding),
126
+ horizontalButtonSpace = horizontalButtonSpace,
127
+ minButtonSize = minButtonSize,
128
+ state = state
129
+ )
130
+ }
81
131
}
82
- PinDisplay (
83
- modifier = Modifier
84
- .fillMaxWidth(),
85
- length = codeLength,
86
- error = error,
87
- )
88
- PinBoard (
132
+ } else {
133
+
134
+ Column (
89
135
modifier = Modifier
90
- .padding(horizontal = 8 .dp)
91
- .padding(top = 32 .dp),
92
- state = state
93
- )
136
+ .fillMaxWidth()
137
+ .fillMaxHeight()
138
+ .padding(it)
139
+ .padding(start = 40 .dp, top = 40 .dp, end = 40 .dp, bottom = 56 .dp),
140
+ verticalArrangement = Arrangement .spacedBy(16 .dp, Alignment .Bottom ),
141
+ horizontalAlignment = Alignment .CenterHorizontally
142
+ ) {
143
+ if (description != null ) {
144
+ Spacer (modifier = Modifier .weight(1f ))
145
+ Box (
146
+ modifier = Modifier .fillMaxWidth(),
147
+ contentAlignment = Alignment .Center
148
+ ) {
149
+ CompositionLocalProvider (
150
+ LocalTextStyle provides MaterialTheme .typography.headlineMedium.copy(
151
+ textAlign = TextAlign .Center
152
+ )
153
+ ) {
154
+ description()
155
+ }
156
+ }
157
+ Spacer (modifier = Modifier .weight(1f ))
158
+ }
159
+ PinDisplay (
160
+ modifier = Modifier
161
+ .fillMaxWidth(),
162
+ length = codeLength,
163
+ error = error,
164
+ )
165
+ PinBoard (
166
+ modifier = Modifier
167
+ .padding(horizontal = 8 .dp)
168
+ .padding(top = 32 .dp),
169
+ state = state
170
+ )
171
+ }
94
172
}
95
173
}
96
174
}
0 commit comments