-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Financial Connections] Compose support. (#5117)
* Adds composable functions. * Adds example. * Updates changelog. * Updates naming to `remember`. * Ktlint fixes. * Regenerates API.
- Loading branch information
1 parent
4390817
commit 3ef8752
Showing
9 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...stripe/android/financialconnections/example/FinancialConnectionsComposeExampleActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.stripe.android.financialconnections.example | ||
|
||
import android.os.Bundle | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.viewModels | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.LinearProgressIndicator | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.stripe.android.financialconnections.example.FinancialConnectionsExampleViewEffect.OpenFinancialConnectionsSheetExample | ||
import com.stripe.android.financialconnections.rememberFinancialConnectionsSheet | ||
|
||
class FinancialConnectionsComposeExampleActivity : AppCompatActivity() { | ||
|
||
private val viewModel by viewModels<FinancialConnectionsExampleViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
FinancialConnectionsScreen() | ||
} | ||
} | ||
|
||
|
||
@Composable | ||
private fun FinancialConnectionsScreen() { | ||
val state: FinancialConnectionsExampleState by viewModel.state.collectAsState() | ||
val viewEffect: FinancialConnectionsExampleViewEffect? by viewModel.viewEffect.collectAsState(null) | ||
val financialConnectionsSheet = rememberFinancialConnectionsSheet(viewModel::onFinancialConnectionsSheetResult) | ||
|
||
LaunchedEffect(viewEffect) { | ||
viewEffect?.let { | ||
when (it) { | ||
is OpenFinancialConnectionsSheetExample -> financialConnectionsSheet.present(it.configuration) | ||
} | ||
} | ||
} | ||
|
||
FinancialConnectionsContent( | ||
state = state, | ||
onButtonClick = { viewModel.startFinancialConnectionsSessionForData() } | ||
) | ||
} | ||
|
||
@Composable | ||
private fun FinancialConnectionsContent( | ||
state: FinancialConnectionsExampleState, | ||
onButtonClick: () -> Unit | ||
) { | ||
Column(modifier = Modifier.padding(horizontal = 10.dp)) { | ||
if (state.loading) { | ||
LinearProgressIndicator( | ||
modifier = Modifier.fillMaxWidth(), | ||
) | ||
} | ||
Button( | ||
onClick = { onButtonClick() }, | ||
) { | ||
Text("Connect Accounts!") | ||
} | ||
|
||
Divider(modifier = Modifier.padding(vertical = 5.dp)) | ||
Text(text = state.status) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.