Skip to content

Commit 4cc21b7

Browse files
committed
dynamic layout for country item added
1 parent 1b0855a commit 4cc21b7

File tree

14 files changed

+236
-136
lines changed

14 files changed

+236
-136
lines changed

README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Add the dependency below to your **module**'s `build.gradle` file:
3535

3636
```gradle
3737
dependencies {
38-
implementation("io.github.androidpoet.countrypicker:0.1.1")
38+
implementation("io.github.androidpoet.countrypicker:$version")
3939
}
4040
```
4141

@@ -45,7 +45,7 @@ For Kotlin Multiplatform, add the dependency below to your **module**'s `build.g
4545
sourceSets {
4646
val commonMain by getting {
4747
dependencies {
48-
implementation("io.github.androidpoet.countrypicker:0.1.1")
48+
implementation("io.github.androidpoet.countrypicker:$version")
4949
}
5050
}
5151
}
@@ -58,27 +58,39 @@ Here's a basic example of how to use the ComposePicker in your Compose Multiplat
5858
```kotlin
5959
@Composable
6060
fun CountryPickerExample() {
61-
var showBottomSheet by remember { mutableStateOf(false) }
6261
var currantCountry by remember { mutableStateOf("") }
63-
62+
var isBottomSheetVisible by remember { mutableStateOf(false) }
6463
CountryPicker(
6564
onCountryChanged = {
6665
currantCountry = it.name + " " + it.flag + " " + it.alpha2
6766
},
6867
onDismiss = {
69-
showBottomSheet = false
68+
isBottomSheetVisible = false
69+
},
70+
itemContent = { country, onClick ->
71+
// pass your own layout here
72+
CountryItem(
73+
name = country.name,
74+
countryCode = country.phoneCountryCode,
75+
flag = country.flag.toString(),
76+
onItemClick = onClick,
77+
itemBackgroundColor = Color.White,
78+
textColor = Color.Black,
79+
currencyCode = country.currencyCode.orEmpty(),
80+
currencySign = country.currencySign.orEmpty(),
81+
)
7082
},
71-
showBottomSheet = showBottomSheet,
83+
isBottomSheetVisible = isBottomSheetVisible,
7284
)
7385

7486
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
7587
Column {
7688
Text(currantCountry, fontSize = 20.sp)
7789

7890
Button(onClick = {
79-
showBottomSheet = !showBottomSheet
91+
isBottomSheetVisible = !isBottomSheetVisible
8092
}) {
81-
Text("open Country Picker", fontSize = 15.sp)
93+
Text("Open Country Picker", fontSize = 15.sp)
8294
}
8395
}
8496
}
@@ -96,15 +108,25 @@ CountryPicker(
96108
currantCountry = it.name + " " + it.flag + " " + it.alpha2
97109
},
98110
onDismiss = {
99-
showBottomSheet = false
111+
isBottomSheetVisible = false
100112
},
101-
showBottomSheet = showBottomSheet,
102-
searchEnabled = false,
103-
itemBackgroundColor = Color.White,
104-
textColor = Color.Black,
105-
searchBarColor = Color.LightGray
113+
itemContent = { country, onClick ->
114+
// pass your own layout here
115+
CountryItem(
116+
name = country.name,
117+
countryCode = country.phoneCountryCode,
118+
flag = country.flag.toString(),
119+
onItemClick = onClick,
120+
itemBackgroundColor = Color.White,
121+
textColor = Color.Black,
122+
currencyCode = country.currencyCode.orEmpty(),
123+
currencySign = country.currencySign.orEmpty(),
124+
)
125+
},
126+
isBottomSheetVisible = isBottomSheetVisible,
106127
)
107128

129+
108130
```
109131

110132
## Contributing

app/api/app.api

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public final class io/androidpoet/countrypickerdemo/BuildConfig {
99

1010
public final class io/androidpoet/countrypickerdemo/ComposableSingletons$MainActivityKt {
1111
public static final field INSTANCE Lio/androidpoet/countrypickerdemo/ComposableSingletons$MainActivityKt;
12-
public static field lambda-1 Lkotlin/jvm/functions/Function3;
13-
public static field lambda-2 Lkotlin/jvm/functions/Function2;
12+
public static field lambda-1 Lkotlin/jvm/functions/Function4;
13+
public static field lambda-2 Lkotlin/jvm/functions/Function3;
1414
public static field lambda-3 Lkotlin/jvm/functions/Function2;
15+
public static field lambda-4 Lkotlin/jvm/functions/Function2;
1516
public fun <init> ()V
16-
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function3;
17-
public final fun getLambda-2$app_release ()Lkotlin/jvm/functions/Function2;
17+
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function4;
18+
public final fun getLambda-2$app_release ()Lkotlin/jvm/functions/Function3;
1819
public final fun getLambda-3$app_release ()Lkotlin/jvm/functions/Function2;
20+
public final fun getLambda-4$app_release ()Lkotlin/jvm/functions/Function2;
1921
}
2022

2123
public final class io/androidpoet/countrypickerdemo/MainActivity : androidx/activity/ComponentActivity {

app/src/main/kotlin/io/androidpoet/countrypickerdemo/MainActivity.kt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import androidx.compose.runtime.remember
2929
import androidx.compose.runtime.setValue
3030
import androidx.compose.ui.Alignment
3131
import androidx.compose.ui.Modifier
32+
import androidx.compose.ui.graphics.Color
3233
import androidx.compose.ui.unit.sp
34+
import io.androidpoet.countrypicker.CountryItem
3335
import io.androidpoet.countrypicker.CountryPicker
34-
import io.androidpoet.countrypicker.CountryUtils.generateCurrencySymbol
3536
import io.androidpoet.countrypickerdemo.ui.theme.CountryPickerDemoTheme
3637

3738
class MainActivity : ComponentActivity() {
@@ -40,31 +41,39 @@ class MainActivity : ComponentActivity() {
4041

4142
setContent {
4243
CountryPickerDemoTheme {
43-
var showBottomSheet by remember { mutableStateOf(false) }
4444
var currantCountry by remember { mutableStateOf("") }
45-
45+
var isBottomSheetVisible by remember { mutableStateOf(false) }
4646
CountryPicker(
4747
onCountryChanged = {
48-
currantCountry =
49-
it.name + " " + it.flag + " " + it.alpha2 + it.currencySign.orEmpty()
50-
51-
println(it.currencySign.orEmpty())
52-
48+
currantCountry = it.name + " " + it.flag + " " + it.alpha2
5349
},
5450
onDismiss = {
55-
showBottomSheet = false
51+
isBottomSheetVisible = false
52+
},
53+
itemContent = { country, onClick ->
54+
// pass your own layout here
55+
CountryItem(
56+
name = country.name,
57+
countryCode = country.phoneCountryCode,
58+
flag = country.flag.toString(),
59+
onItemClick = onClick,
60+
itemBackgroundColor = Color.White,
61+
textColor = Color.Black,
62+
currencyCode = country.currencyCode.orEmpty(),
63+
currencySign = country.currencySign.orEmpty(),
64+
)
5665
},
57-
showBottomSheet = showBottomSheet,
66+
isBottomSheetVisible = isBottomSheetVisible,
5867
)
5968

6069
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
6170
Column {
6271
Text(currantCountry, fontSize = 20.sp)
6372

6473
Button(onClick = {
65-
showBottomSheet = !showBottomSheet
74+
isBottomSheetVisible = !isBottomSheetVisible
6675
}) {
67-
Text("open Country Picker", fontSize = 15.sp)
76+
Text("Open Country Picker", fontSize = 15.sp)
6877
}
6978
}
7079
}

baselineprofile-app/api/baselineprofile-app.api

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ public final class io/androidpoet/countrypicker/baselineprofile/app/BuildConfig
77

88
public final class io/androidpoet/countrypicker/baselineprofile/app/ComposableSingletons$MainActivityKt {
99
public static final field INSTANCE Lio/androidpoet/countrypicker/baselineprofile/app/ComposableSingletons$MainActivityKt;
10-
public static field lambda-1 Lkotlin/jvm/functions/Function3;
11-
public static field lambda-2 Lkotlin/jvm/functions/Function2;
10+
public static field lambda-1 Lkotlin/jvm/functions/Function4;
11+
public static field lambda-2 Lkotlin/jvm/functions/Function3;
12+
public static field lambda-3 Lkotlin/jvm/functions/Function2;
1213
public fun <init> ()V
13-
public final fun getLambda-1$baselineprofile_app_release ()Lkotlin/jvm/functions/Function3;
14-
public final fun getLambda-2$baselineprofile_app_release ()Lkotlin/jvm/functions/Function2;
14+
public final fun getLambda-1$baselineprofile_app_release ()Lkotlin/jvm/functions/Function4;
15+
public final fun getLambda-2$baselineprofile_app_release ()Lkotlin/jvm/functions/Function3;
16+
public final fun getLambda-3$baselineprofile_app_release ()Lkotlin/jvm/functions/Function2;
1517
}
1618

1719
public final class io/androidpoet/countrypicker/baselineprofile/app/MainActivity : androidx/activity/ComponentActivity {

baselineprofile-app/src/main/kotlin/io/androidpoet/countrypicker/baselineprofile/app/MainActivity.kt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import androidx.compose.runtime.remember
2929
import androidx.compose.runtime.setValue
3030
import androidx.compose.ui.Alignment
3131
import androidx.compose.ui.Modifier
32+
import androidx.compose.ui.graphics.Color
3233
import androidx.compose.ui.unit.sp
34+
import io.androidpoet.countrypicker.CountryItem
3335
import io.androidpoet.countrypicker.CountryPicker
3436

3537
class MainActivity : ComponentActivity() {
@@ -38,23 +40,39 @@ class MainActivity : ComponentActivity() {
3840

3941
setContent {
4042
Box {
41-
var showBottomSheet by remember { mutableStateOf(false) }
4243
var currantCountry by remember { mutableStateOf("") }
43-
44-
CountryPicker(onCountryChanged = {
45-
currantCountry = it.name + " " + it.flag + " " + it.alpha2
46-
}, onDismiss = {
47-
showBottomSheet = false
48-
}, showBottomSheet = showBottomSheet)
44+
var isBottomSheetVisible by remember { mutableStateOf(false) }
45+
CountryPicker(
46+
onCountryChanged = {
47+
currantCountry = it.name + " " + it.flag + " " + it.alpha2
48+
},
49+
onDismiss = {
50+
isBottomSheetVisible = false
51+
},
52+
itemContent = { country, onClick ->
53+
// pass your own layout here
54+
CountryItem(
55+
name = country.name,
56+
countryCode = country.phoneCountryCode,
57+
flag = country.flag.toString(),
58+
onItemClick = onClick,
59+
itemBackgroundColor = Color.White,
60+
textColor = Color.Black,
61+
currencyCode = country.currencyCode.orEmpty(),
62+
currencySign = country.currencySign.orEmpty(),
63+
)
64+
},
65+
isBottomSheetVisible = isBottomSheetVisible,
66+
)
4967

5068
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
5169
Column {
5270
Text(currantCountry, fontSize = 20.sp)
5371

5472
Button(onClick = {
55-
showBottomSheet = !showBottomSheet
73+
isBottomSheetVisible = !isBottomSheetVisible
5674
}) {
57-
Text("open Country Picker", fontSize = 15.sp)
75+
Text("Open Country Picker", fontSize = 15.sp)
5876
}
5977
}
6078
}

buildSrc/src/main/kotlin/io/androidpoet/countrypicker/Configuration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Configuration {
66
const val minSdk = 21
77
const val majorVersion = 0
88
const val minorVersion = 1
9-
const val patchVersion = 3
9+
const val patchVersion = 4
1010
const val versionName = "$majorVersion.$minorVersion.$patchVersion"
1111
const val versionCode = 1
1212
const val snapshotVersionName = "$majorVersion.$minorVersion.${patchVersion + 1}-SNAPSHOT"

countrypicker/api/android/countrypicker.api

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ public final class io/androidpoet/countrypicker/CountriesListKt {
1616
public final class io/androidpoet/countrypicker/Country {
1717
public static final field $stable I
1818
public static final field Companion Lio/androidpoet/countrypicker/Country$Companion;
19-
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
20-
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
19+
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
20+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2121
public final fun component1 ()Ljava/lang/String;
2222
public final fun component2 ()Ljava/lang/String;
2323
public final fun component3 ()Ljava/lang/String;
2424
public final fun component4 ()Ljava/lang/String;
2525
public final fun component5 ()Ljava/lang/String;
2626
public final fun component6 ()Ljava/lang/String;
27-
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/androidpoet/countrypicker/Country;
28-
public static synthetic fun copy$default (Lio/androidpoet/countrypicker/Country;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/androidpoet/countrypicker/Country;
27+
public final fun component7 ()Ljava/lang/String;
28+
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/androidpoet/countrypicker/Country;
29+
public static synthetic fun copy$default (Lio/androidpoet/countrypicker/Country;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/androidpoet/countrypicker/Country;
2930
public fun equals (Ljava/lang/Object;)Z
3031
public final fun getAlpha2 ()Ljava/lang/String;
3132
public final fun getCurrencyCode ()Ljava/lang/String;
33+
public final fun getCurrencySign ()Ljava/lang/String;
3234
public final fun getFlag ()Ljava/lang/String;
3335
public final fun getLocaleForICU ()Ljava/lang/String;
3436
public final fun getName ()Ljava/lang/String;
@@ -53,30 +55,57 @@ public final class io/androidpoet/countrypicker/Country$Companion {
5355
public final fun serializer ()Lkotlinx/serialization/KSerializer;
5456
}
5557

58+
public final class io/androidpoet/countrypicker/CountryItemKt {
59+
public static final fun CountryItem-WMdw5o4 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JJLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;I)V
60+
}
61+
5662
public final class io/androidpoet/countrypicker/CountryPickerKt {
57-
public static final fun CountryPicker-vtnTUvE (Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function0;ZJJJLandroidx/compose/runtime/Composer;II)V
63+
public static final fun CountryPicker-vRFhKjU (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ZJJZLkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V
5864
}
5965

6066
public final class io/androidpoet/countrypicker/CountryPickerState {
6167
public static final field $stable I
68+
public static final field Companion Lio/androidpoet/countrypicker/CountryPickerState$Companion;
6269
public fun <init> ()V
63-
public fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;)V
64-
public synthetic fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
70+
public fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;)V
71+
public synthetic fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
6572
public final fun component1 ()Ljava/util/List;
6673
public final fun component2 ()Lio/androidpoet/countrypicker/Country;
67-
public final fun component3 ()Z
68-
public final fun component4 ()Ljava/lang/String;
69-
public final fun copy (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;)Lio/androidpoet/countrypicker/CountryPickerState;
70-
public static synthetic fun copy$default (Lio/androidpoet/countrypicker/CountryPickerState;Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;ILjava/lang/Object;)Lio/androidpoet/countrypicker/CountryPickerState;
74+
public final fun copy (Ljava/util/List;Lio/androidpoet/countrypicker/Country;)Lio/androidpoet/countrypicker/CountryPickerState;
75+
public static synthetic fun copy$default (Lio/androidpoet/countrypicker/CountryPickerState;Ljava/util/List;Lio/androidpoet/countrypicker/Country;ILjava/lang/Object;)Lio/androidpoet/countrypicker/CountryPickerState;
7176
public fun equals (Ljava/lang/Object;)Z
7277
public final fun getCountries ()Ljava/util/List;
7378
public final fun getCurrentCountry ()Lio/androidpoet/countrypicker/Country;
74-
public final fun getError ()Ljava/lang/String;
7579
public fun hashCode ()I
76-
public final fun isLoading ()Z
7780
public fun toString ()Ljava/lang/String;
7881
}
7982

83+
public synthetic class io/androidpoet/countrypicker/CountryPickerState$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
84+
public static final field $stable I
85+
public static final field INSTANCE Lio/androidpoet/countrypicker/CountryPickerState$$serializer;
86+
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
87+
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lio/androidpoet/countrypicker/CountryPickerState;
88+
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
89+
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
90+
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lio/androidpoet/countrypicker/CountryPickerState;)V
91+
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
92+
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
93+
}
94+
95+
public final class io/androidpoet/countrypicker/CountryPickerState$Companion {
96+
public final fun serializer ()Lkotlinx/serialization/KSerializer;
97+
}
98+
99+
public final class io/androidpoet/countrypicker/CountryUtils {
100+
public static final field $stable I
101+
public static final field INSTANCE Lio/androidpoet/countrypicker/CountryUtils;
102+
public final fun generateCurrencySymbol (Ljava/lang/String;)Ljava/lang/String;
103+
}
104+
105+
public final class io/androidpoet/countrypicker/CurrencySymbolKt {
106+
public static final fun getCurrencySymbols ()Ljava/util/Map;
107+
}
108+
80109
public final class io/androidpoet/countrypicker/ListSaverKt {
81110
public static final fun getCountryPickerStateSaver ()Landroidx/compose/runtime/saveable/Saver;
82111
public static final fun rememberCountryPickerState (Landroidx/compose/runtime/Composer;I)Landroidx/compose/runtime/MutableState;

0 commit comments

Comments
 (0)