Skip to content

Instantly share code, notes, and snippets.

@RandyWei
RandyWei / PagerWithTabRow.kt
Created March 24, 2022 02:54
Tab 和 Pager 联动
//需要添加依赖
//implementation "com.google.accompanist:accompanist-pager:0.24.4-alpha"
//implementation "com.google.accompanist:accompanist-pager-indicators:0.24.4-alpha"
@OptIn(ExperimentalPagerApi::class)
@Composable
fun PagerWithTabRow() {
val tabs = listOf("首页", "图片", "国内", "国际", "数读", "军事", "航空", "传媒研究院", "政务", "公益", "媒体")
val pagerState = rememberPagerState()
@RandyWei
RandyWei / Stepper.kt
Created February 18, 2022 01:03
Stepper
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowLeft
@RandyWei
RandyWei / TimelineDemo.swift
Last active January 19, 2022 06:13
时间轴优化版
struct TimelineDemo: View {
var body: some View {
ScrollView{
VStack(spacing: 0){
TimelineItemView(first: true)
ForEach(0..<10){_ in
TimelineItemView()
}
TimelineItemView(last: true)
}
@RandyWei
RandyWei / ScrollViewDemo.swift
Created December 28, 2021 00:48
带 Header 的 ScrollView
struct ScrollViewDemo: View {
//ScorllView滚动偏移量
@State private var offset: CGFloat = 0
//header 最大高度
private let headerMaxHeight: CGFloat = 250
//计算 header 的偏移量
private var headerOffset: CGFloat {
@RandyWei
RandyWei / SiderMenuDemo.swift
Last active July 24, 2023 11:14
SwiftUI 侧边菜单简单示例
import SwiftUI
struct ContentView: View {
//划动偏移量
@GestureState var offset:CGFloat = 0
//滑动应该停留在某个点
//停留点: 屏幕宽度的3/5
let maxOffset:CGFloat = UIScreen.main.bounds.width * 3 / 5
@RandyWei
RandyWei / Image 设置渐变色.swift
Last active September 2, 2021 07:04
Image 设置渐变色
import SwiftUI
extension View {
func gradientForeground<GradientForeground>(_ gragient: GradientForeground) -> some View where GradientForeground : View{
self.overlay(gragient)
.mask(self)
}
}
struct ContentView: View {
@RandyWei
RandyWei / SwiftUI 时间轴.swift
Last active September 2, 2021 07:05
SwiftUI 时间轴fixedSize 实现
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollView{
VStack{
ForEach(0..<10){_ in
TimelineItemView()
@RandyWei
RandyWei / SwiftUI 时间轴.swift
Last active September 2, 2021 07:05
SwiftUI 时间轴PreferenceKey实现方式
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollView{
VStack{
ForEach(0..<10){_ in
TimelineItemView()
}