Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HapticFeedback in IconButton #1807

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme

Expand All @@ -48,11 +50,17 @@ fun NiaIconToggleButton(
icon: @Composable () -> Unit,
checkedIcon: @Composable () -> Unit = icon,
) {
val haptics = LocalHapticFeedback.current
// TODO: File bug
// Can't use regular IconToggleButton as it doesn't include a shape (appears square)
FilledIconToggleButton(
checked = checked,
onCheckedChange = onCheckedChange,
onCheckedChange = { isChecked ->
haptics.performHapticFeedback(
if (isChecked) HapticFeedbackType.ToggleOn else HapticFeedbackType.ToggleOff
)
onCheckedChange(isChecked)
},
modifier = modifier,
enabled = enabled,
colors = IconButtonDefaults.iconToggleButtonColors(
Expand Down
4 changes: 3 additions & 1 deletion core/ui/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest />
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>