ποΈ CMPToast is a lightweight and easy-to-use library for displaying toast messages in Compose Multiplatform projects.
To use CMPToast in your Compose Multiplatform project, add the following dependency to your build.gradle.kts
:
commonMain.dependencies {
implementation("network.chaintech:cmptoast:1.0.4")
}
Note : Create an Application Class and add the following line (Otherwise you might face context error):
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
multiplatform.network.cmptoast.AppContext.apply { set(applicationContext) }
}
}
Also if you are getting Manifest Merger Failed issue, add the following to your Android Manifest file:
tools:replace="android:name"
tools:replace="android:allowBackup"
To display a simple toast:
showToast(
message = "This is a Toast"
)
Watch the demo below to see CMPToast in action:
To show a short-duration toast:
showToast(
message = "This is Short Toast",
backgroundColor = Color.White,
textColor = Color.Black,
duration = ToastDuration.Short
)
To show a long-duration toast:
showToast(
message = "This is Long Toast",
backgroundColor = Color.White,
textColor = Color.Black,
duration = ToastDuration.Long
)
To show toast at top of the screen:
showToast(
message = "This is Top Toast",
backgroundColor = Color.White,
textColor = Color.Black,
gravity = ToastGravity.Top
)
To show toast at center of the screen:
showToast(
message = "This is Center Toast",
backgroundColor = Color.White,
textColor = Color.Black,
gravity = ToastGravity.Center
)
To show a colored toast:
showToast(
message = "This is Colored Toast",
backgroundColor = Color(0xFF27AD9D)
)
Property | Type | Description |
---|---|---|
message | String |
The message to be displayed in the toast. |
gravity | ToastGravity |
The position of the toast. |
backgroundColor | Color |
The background color of the toast. |
textColor | Color |
The color of the message text. |
duration | ToastDuration |
The duration of the toast. |
padding | ToastPadding? |
Internal padding for the toast content. |
textSize | TextUnit |
The size of the text. |
topPadding | Int |
Padding between toast and top of screen. |
bottomPadding | Int |
Padding between toast and bottom of screen. |
cornerRadius | Int? |
For rounding the corners of the toast. |
CMPToast currently supports the following platforms:
For an in-depth guide and detailed explanation, check out our comprehensive Medium Blog Post.
Stay connected and keep up with our latest innovations! πΌ Let's innovate together!
Copyright 2023 Mobile Innovation Network
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.