9
9
*/
10
10
package org.mifospay.core.designsystem.component
11
11
12
- import android.content.res.Configuration
13
12
import androidx.compose.foundation.layout.Box
14
13
import androidx.compose.foundation.layout.fillMaxSize
15
14
import androidx.compose.foundation.layout.size
16
15
import androidx.compose.material3.LocalAbsoluteTonalElevation
17
16
import androidx.compose.material3.Surface
18
17
import androidx.compose.runtime.Composable
19
18
import androidx.compose.runtime.CompositionLocalProvider
20
- import androidx.compose.runtime.getValue
21
- import androidx.compose.runtime.rememberUpdatedState
22
19
import androidx.compose.ui.Modifier
23
- import androidx.compose.ui.draw.drawWithCache
24
- import androidx.compose.ui.geometry.Offset
25
- import androidx.compose.ui.graphics.Brush
26
20
import androidx.compose.ui.graphics.Color
27
- import androidx.compose.ui.tooling.preview.Preview
28
21
import androidx.compose.ui.unit.Dp
29
22
import androidx.compose.ui.unit.dp
23
+ import org.jetbrains.compose.ui.tooling.preview.Preview
30
24
import org.mifospay.core.designsystem.theme.GradientColors
31
25
import org.mifospay.core.designsystem.theme.LocalBackgroundTheme
32
26
import org.mifospay.core.designsystem.theme.LocalGradientColors
33
27
import org.mifospay.core.designsystem.theme.MifosTheme
34
- import kotlin.math.tan
35
28
36
29
/* *
37
30
* The main background for the app.
@@ -66,14 +59,13 @@ fun MifosBackground(
66
59
* @param gradientColors The gradient colors to be rendered.
67
60
* @param content The background content.
68
61
*/
62
+ // TODO:: Fix the gradient background based on NewUI
69
63
@Composable
70
64
fun MifosGradientBackground (
71
65
modifier : Modifier = Modifier ,
72
66
gradientColors : GradientColors = LocalGradientColors .current,
73
67
content : @Composable () -> Unit ,
74
68
) {
75
- val currentTopColor by rememberUpdatedState(gradientColors.top)
76
- val currentBottomColor by rememberUpdatedState(gradientColors.bottom)
77
69
Surface (
78
70
color = if (gradientColors.container == Color .Unspecified ) {
79
71
Color .Transparent
@@ -84,48 +76,7 @@ fun MifosGradientBackground(
84
76
) {
85
77
Box (
86
78
Modifier
87
- .fillMaxSize()
88
- .drawWithCache {
89
- // Compute the start and end coordinates such that the gradients are angled 11.06
90
- // degrees off the vertical axis
91
- val offset = size.height * tan(
92
- Math
93
- .toRadians(11.06 )
94
- .toFloat(),
95
- )
96
-
97
- val start = Offset (size.width / 2 + offset / 2 , 0f )
98
- val end = Offset (size.width / 2 - offset / 2 , size.height)
99
-
100
- // Create the top gradient that fades out after the halfway point vertically
101
- val topGradient = Brush .linearGradient(
102
- 0f to if (currentTopColor == Color .Unspecified ) {
103
- Color .Transparent
104
- } else {
105
- currentTopColor
106
- },
107
- 0.724f to Color .Transparent ,
108
- start = start,
109
- end = end,
110
- )
111
- // Create the bottom gradient that fades in before the halfway point vertically
112
- val bottomGradient = Brush .linearGradient(
113
- 0.2552f to Color .Transparent ,
114
- 1f to if (currentBottomColor == Color .Unspecified ) {
115
- Color .Transparent
116
- } else {
117
- currentBottomColor
118
- },
119
- start = start,
120
- end = end,
121
- )
122
-
123
- onDrawBehind {
124
- // There is overlap here, so order is important
125
- drawRect(topGradient)
126
- drawRect(bottomGradient)
127
- }
128
- },
79
+ .fillMaxSize(),
129
80
) {
130
81
content()
131
82
}
@@ -136,8 +87,7 @@ fun MifosGradientBackground(
136
87
* Multipreview annotation that represents light and dark themes. Add this annotation to a
137
88
* composable to render the both themes.
138
89
*/
139
- @Preview(uiMode = Configuration .UI_MODE_NIGHT_NO , name = " Light theme" )
140
- @Preview(uiMode = Configuration .UI_MODE_NIGHT_YES , name = " Dark theme" )
90
+ @Preview
141
91
annotation class ThemePreviews
142
92
143
93
@ThemePreviews
0 commit comments