Skip to content

Instantly share code, notes, and snippets.

View GerardPaligot's full-sized avatar

Gérard Paligot GerardPaligot

View GitHub Profile
var body: some View {
VStack {
// Generate form UI
Form {
// Generate section UI
Section {
TextField("Your email address*", text: $email)
.keyboardType(.emailAddress)
TextField("Your first name*", text: $firstName)
TextField("Your last name*", text: $lastName)
struct Networking: View {
@ObservedObject var viewModel: NetworkingViewModel
// state to displau a sheet
@State private var isPresentingScanner = false
var body: some View {
let uiState = viewModel.uiState
NavigationView {
Group {
// AppView.swift - Declare the tabs navigation.
TabView {
AgendaVM(agendaRepository: agendaRepository)
.tabItem {
Label("Agenda", systemImage: "calendar")
}
NetworkingVM(userRepository: userRepository)
.tabItem {
Label("Networking", systemImage: "person.2")
@Composable
fun Chrono(
seconds: Int,
modifier: Modifier = Modifier
) {
val nbMarker = 60
val progressAngle by animateFloatAsState(
targetValue = 360f / 30f * seconds,
animationSpec = tween(500)
)
val progressAngle by animateFloatAsState(
targetValue = 360f / 30f * seconds,
animationSpec = tween(500)
)
val markerActives by animateFloatAsState(
targetValue = nbMarker / 30f * seconds,
animationSpec = tween(500)
)
@Composable
fun animateFloatAsState(
targetValue: Float,
animationSpec: AnimationSpec<Float> = defaultAnimation,
visibilityThreshold: Float = 0.01f,
finishedListener: ((Float) -> Unit)? = null
)
class TimerViewModel : ViewModel() {
private var job: Job? = null
private val _times = MutableStateFlow(0)
val times = _times.asStateFlow()
fun start(times: Int = 30) {
if (_times.value == 0) _times.value = times
job?.cancel()
job = viewModelScope.launch(Dispatchers.IO) {
while (isActive) {
job = viewModelScope.launch(Dispatchers.IO) {
while (isActive) {
if (_times.value <= 0) {
job?.cancel()
return@launch
}
delay(timeMillis = 1000)
_times.value -= 1
}
}
@Composable
internal fun Marker(
angle: Int,
active: Boolean,
modifier: Modifier = Modifier
) {
Box(
modifier
.fillMaxSize()
.drawBehind {
@Composable
internal fun CircleProgress(
angle: Float,
modifier: Modifier = Modifier
) {
Box(
modifier
.fillMaxSize()
.drawBehind {
drawArc(