An open API service indexing awesome lists of open source software.

https://github.com/kibotu/webviewbottomsheet

A clean Android demo showcasing WebView integration within a Material Design Bottom Sheet. Perfect reference for embedding web content with native UX patterns.
https://github.com/kibotu/webviewbottomsheet

android android-kotlin android-webview bottom-sheet jetpack-compose mobile-development modal nestedscrolling webview

Last synced: 8 days ago
JSON representation

A clean Android demo showcasing WebView integration within a Material Design Bottom Sheet. Perfect reference for embedding web content with native UX patterns.

Awesome Lists containing this project

README

          

# WebView Bottom Sheet Demo
[![Build](https://github.com/kibotu/WebViewBottomSheet/actions/workflows/build.yml/badge.svg)](https://github.com/kibotu/WebViewBottomSheet/actions/workflows/build.yml)

---

## ๐Ÿš€ What is WebView Bottom Sheet?

**WebView Bottom Sheet** is a clean, minimal demonstration of Android's powerful `WebView` component housed within a Material Design **Bottom Sheet**. It showcases how to elegantly integrate web content into your native Android app while maintaining a modern, user-friendly interface.

This project serves as a reference implementation for developers exploring the intersection of native Android development and web technologies.

---

## ๐Ÿ’ก Why Use WebView in a Bottom Sheet?

### The Problem

Many Android developers struggle with:
- โœ… Seamlessly embedding web views
- โœ… Managing memory and lifecycle correctly
- โœ… Creating intuitive user interactions
- โœ… Maintaining native app feel

### The Solution

A beautifully crafted example demonstrating best practices for:
- ๐Ÿ“ฑ **Native-feeling UI** โ€” Bottom sheets slide smoothly from the bottom
- ๐Ÿ”„ **Proper lifecycle management** โ€” WebView handles pause/resume/destroy correctly
- ๐ŸŽจ **Material Design 3** โ€” Modern, polished aesthetics
- โšก **Performance** โ€” Optimized memory and resource usage
- ๐ŸŒ **Full web support** โ€” JavaScript, DOM, media playback enabled

---

## ๐ŸŽฅ Demo Video

[![Demo](https://github.com/user-attachments/assets/27b3e23c-0172-4462-a797-dcb884ad5817)](https://github.com/user-attachments/assets/27b3e23c-0172-4462-a797-dcb884ad5817)

---

## โœจ Key Features

| Feature | Description |
|---------|-------------|
| **Material Design 3** | Modern Material You theming with custom colors |
| **Bottom Sheet Dialog** | Smooth, gesture-driven animations |
| **Full WebView Support** | JavaScript, DOM storage, zoom controls |
| **Edge-to-Edge Display** | Immersive UI experience |
| **Proper Cleanup** | Memory-efficient WebView destruction |
| **Intercept Handling** | Parent scroll intercept logic |
| **Transparent Background** | Clean visual integration |

---

### Core Dependencies

- **AndroidX Core** โ€” Foundation utilities
- **Jetpack Compose** โ€” Modern UI toolkit
- **Material 3 Components** โ€” Beautiful UI elements
- **WebView** โ€” Full web rendering capabilities
- **Fragment** โ€” Bottom sheet dialog support

---

## ๐Ÿ“ฆ Getting Started

### Prerequisites

- **Android Studio** โ€” Arctic Fox 2020.3.1 or later
- **JDK 17** โ€” Required for compilation
- **Android SDK** โ€” API 24+ (minSdk)
- **Git** โ€” For cloning the repository

### Quick Start

```bash
# Clone the repository
git clone https://github.com/kibotu/WebViewBottomSheet.git
cd WebViewBottomSheet

# Install dependencies
./gradlew dependencies

# Build debug APK
./gradlew assembleDebug

# Install on device
adb install app/build/outputs/apk/debug/app-debug.apk
```

### Build Configuration

The project uses:
- **Kotlin DSL** โ€” Modern build scripting
- **Gradle Caching** โ€” Optimized build times
- **Daemon Enabled** โ€” Faster incremental builds
- **Configuration Cache** โ€” Consistent builds across environments

---

## ๐Ÿš€ Installation

### Debug Build

1. Connect your device or start an emulator
2. Run the app:
```bash
./gradlew installDebug
```

### Release Build

```bash
./gradlew assembleRelease
```

> **Note:** Release builds require signing configuration in `local.properties`

### Deploy to Device

```bash
# Install APK
adb install app/build/outputs/apk/debug/app-debug.apk

# Install and replace
adb install -r app/build/outputs/apk/debug/app-debug.apk
```

---

## ๐ŸŽฏ How It Works

### Architecture Overview

```
MainActivity
โ”œโ”€โ”€ StartScreen (Compose UI)
โ””โ”€โ”€ WebViewBottomSheetFragment (Bottom Sheet Dialog)
โ””โ”€โ”€ WebView (Full web rendering)
```

### Key Implementation Details

#### Bottom Sheet Dialog

```kotlin
class WebViewBottomSheetFragment : BottomSheetDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
BottomSheetDialog(requireContext(), R.style.WebViewBottomSheet)
}
```

#### WebView Configuration

```kotlin
web.settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
loadWithOverviewMode = true
useWideViewPort = true
mediaPlaybackRequiresUserGesture = false
}
```

#### Lifecycle Management

```kotlin
override fun onDestroyView() {
webView?.apply {
stopLoading()
loadUrl("about:blank")
(parent as? ViewGroup)?.removeView(this)
destroy()
}
webView = null
}
```

---

## ๐Ÿ“ Project Structure

```
WebViewBottomSheet/
โ”œโ”€โ”€ app/
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ”‚ โ””โ”€โ”€ main/
โ”‚ โ”‚ โ”œโ”€โ”€ java/net/kibotu/webviewbottomsheet/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ MainActivity.kt
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ WebViewBottomSheetFragment.kt
โ”‚ โ”‚ โ”œโ”€โ”€ res/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ layout/
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ fragment_webview_bottom_sheet.xml
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ values/
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ colors.xml
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ strings.xml
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ themes.xml
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ xml/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ backup_rules.xml
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ data_extraction_rules.xml
โ”‚ โ”‚ โ””โ”€โ”€ keepRules/
โ”‚ โ”‚ โ””โ”€โ”€ rules.keep
โ”‚ โ””โ”€โ”€ build.gradle.kts
โ”œโ”€โ”€ build.gradle.kts
โ”œโ”€โ”€ settings.gradle.kts
โ””โ”€โ”€ gradle.properties
```

---

## ๐Ÿงช Testing

### Unit Tests

```bash
./gradlew test
```

### Instrumentation Tests

```bash
./gradlew connectedAndroidTest
```

### Linting

```bash
./gradlew lint
```

---

## ๐ŸŒ Demo URL

The app loads: **https://trail.kibotu.net**

> This demonstrates a fully functional WebView with JavaScript and interactive content.

---

## ๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

1. **Fork** the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Code Style

- โœ… Kotlin idiomatic patterns
- โœ… Material Design guidelines
- โœ… Android best practices
- โœ… Clear, concise comments

---

## ๐Ÿ“ž Support

Having issues or questions? Open an [issue](https://github.com/kibotu/WebViewBottomSheet/issues) on GitHub.

---

**Made with โค๏ธ by kibotu**



GitHub