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

Fix: [Capacitor] Set overscroll background color from theme #2594

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1a1943e
Add changes to prevent ios bounce.
Nov 16, 2024
fe721c1
Add updated css to panda.config file.
Nov 18, 2024
fdec688
Lint
Nov 18, 2024
a9a1437
Lint
Nov 18, 2024
15ad477
Lint
Nov 18, 2024
89b6c1d
Final lint
Nov 18, 2024
1c95f1f
Save progress
Nov 26, 2024
c0a9da7
Ignore file
Nov 26, 2024
4611d74
Removed custom plugin add.
Nov 26, 2024
69f998a
Save progress
Nov 26, 2024
116cc0d
Remove security issues.
Nov 26, 2024
932b5fd
Remove,
Nov 26, 2024
439f1db
Ignore lint
Nov 26, 2024
12b5ddb
Add ignores
Nov 26, 2024
e3978e0
Fix styling
Nov 26, 2024
dcfa432
Add file
Nov 26, 2024
fee5e12
Add file
Nov 26, 2024
a2642e2
Fix
Nov 26, 2024
973195d
Add webview plugin
Nov 26, 2024
a3d59d0
Remove node_modules
Nov 26, 2024
a5941fd
Remove node modules
Nov 26, 2024
e40ae4e
Save progress
Nov 26, 2024
ae0af6d
Adjustments before rebase
Nov 26, 2024
17a3b0c
Add fix for updating webview for loaded app. Need reload of window.
Nov 26, 2024
8ab995e
Fix lint
Nov 26, 2024
ceae07d
Add files to gitignore
Nov 26, 2024
7016b54
Remove commentted code
Nov 26, 2024
2fd062c
Update lock
Nov 27, 2024
2ceac4b
Test
Nov 27, 2024
dfb8e5c
Revert
Nov 27, 2024
671a23c
Add refresh only on capacitor
Nov 27, 2024
7518d80
Test
Nov 27, 2024
bd3e2f8
Remove yarn.lock install of .webview plugin due to errors with yarn
Nov 27, 2024
e01185e
Save progress
Nov 27, 2024
0982e2a
Fix
Nov 27, 2024
600e44b
Revert
Nov 27, 2024
b26c87d
S
Nov 27, 2024
95864fc
ci: fix checksum of webview-background dependency
trevinhofmann Nov 30, 2024
d8914c6
Resolve webview-background to local package.
raineorshine Nov 30, 2024
a4ab57d
Merge branch 'main' into bug-issue-1700
raineorshine Nov 30, 2024
01fc1b8
Add code review changes.
Dec 22, 2024
f6f8829
Add updated yarn lock
Dec 23, 2024
0e2cba1
Try to sync packages with github checksum value.
Dec 24, 2024
d0e3e1b
Save checksum change
Dec 24, 2024
e4efcf2
Add fix for breaking build
Dec 26, 2024
a30a48a
Add fix to lint.
Dec 26, 2024
d439dbb
ci: fix checksum of webview-background-dependency again
trevinhofmann Dec 28, 2024
91635d2
Readd code to switch theme after startup.
Dec 30, 2024
a593e29
Remove comment.
Jan 1, 2025
ea94d1b
Add changes for ios top safe area.
Jan 3, 2025
710b932
Merge branch 'main' into bug-issue-1700
msdewitt Jan 3, 2025
8cabd67
Add changes to puppeteer console.
Jan 3, 2025
1c2cd5f
Fix lint errors
Jan 3, 2025
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
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ __diff_output__

## PandaCSS
styled-system
styled-system-studio
styled-system-studio

## Custom Capacitor Plugin
/packages/webview/node_modules
/packages/webview/.DS_Store
/packages/webview/xcuserdata/
/packages/webview/DerivedData/
/packages/webview/.swiftpm/configuration/registries.json
/packages/webview/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
/packages/webview/.netrc

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
docs
LICENSE.md
packages
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation project(':capacitor-clipboard')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-status-bar')
implementation project(':webview-background')

}

Expand Down
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor

include ':capacitor-status-bar'
project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android')

include ':webview-background'
project(':webview-background').projectDir = new File('../node_modules/webview-background/android')
msdewitt marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default [
{
ignores: [
'node_modules/**',
'packages',
'**/styled-system/*',
'**/ios/*',
'**/android/**',
Expand Down
1 change: 1 addition & 0 deletions ios/App/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
}


msdewitt marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def capacitor_pods
pod 'CapacitorClipboard', :path => '../../node_modules/@capacitor/clipboard'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
pod 'WebviewBackground', :path => '../../node_modules/webview-background'
end

target 'App' do
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"allowed-schemes": [
"https:",
"git+https:",
"file:",
"npm:",
"patch:",
"workspace:"
Expand Down Expand Up @@ -133,6 +134,7 @@
"ts-key-enum": "^2.0.12",
"use-onclickoutside": "^0.4.1",
"vite-plugin-html": "^3.2.2",
"webview-background": "./packages/webview",
"workbox-build": "^7.1.1",
"workbox-core": "^7.1.0",
"workbox-expiration": "^7.1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/webview/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
dist
5 changes: 5 additions & 0 deletions packages/webview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

/node_modules
.DS_Store
.env*.local
2 changes: 2 additions & 0 deletions packages/webview/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
dist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>WebviewBackground.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
52 changes: 52 additions & 0 deletions packages/webview/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Contributing

This guide provides instructions for contributing to this Capacitor plugin.

## Developing

### Local Setup

1. Fork and clone the repo.
1. Install the dependencies.

```shell
npm install
```

1. Install SwiftLint if you're on macOS.

```shell
brew install swiftlint
```

### Scripts

#### `npm run build`

Build the plugin web assets and generate plugin API documentation using [`@capacitor/docgen`](https://github.com/ionic-team/capacitor-docgen).

It will compile the TypeScript code from `src/` into ESM JavaScript in `dist/esm/`. These files are used in apps with bundlers when your plugin is imported.

Then, Rollup will bundle the code into a single file at `dist/plugin.js`. This file is used in apps without bundlers by including it as a script in `index.html`.

#### `npm run verify`

Build and validate the web and native projects.

This is useful to run in CI to verify that the plugin builds for all platforms.

#### `npm run lint` / `npm run fmt`

Check formatting and code quality, autoformat/autofix if possible.

This template is integrated with ESLint, Prettier, and SwiftLint. Using these tools is completely optional, but the [Capacitor Community](https://github.com/capacitor-community/) strives to have consistent code style and structure for easier cooperation.

## Publishing

There is a `prepublishOnly` hook in `package.json` which prepares the plugin before publishing, so all you need to do is run:

```shell
npm publish
```

> **Note**: The [`files`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files) array in `package.json` specifies which files get published. If you rename files/directories or add files elsewhere, you may need to update it.
14 changes: 14 additions & 0 deletions packages/webview/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "capacitor-swift-pm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ionic-team/capacitor-swift-pm.git",
"state" : {
"branch" : "main",
"revision" : "2827600e5da84dcfca0339c987e5a8394d6b22f9"
}
}
],
"version" : 2
}
24 changes: 24 additions & 0 deletions packages/webview/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "WebviewBackground",
platforms: [.iOS(.v13)],
products: [
.library(
name: "WebviewBackground",
targets: ["WebviewBackgroundPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
],
targets: [
.target(
name: "WebviewBackgroundPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/WebviewBackgroundPlugin")
]
)
35 changes: 35 additions & 0 deletions packages/webview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# webview-background

A small plugin to change the background of a webview.

## Install

```bash
npm install webview-background
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we used yarn (possibly other tools/libraries?) consistently with the main project, but I am fine with this if @raineorshine doesn't mind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be preferable to use the same package manager throughout the project.

Originally suggested here: #2594 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msdewitt -- We still have the package-lock.json / npm configuration in this package. Can we please switch to yarn?

npx cap sync
```

## API

<docgen-index>

* [`changeBackgroundColor(...)`](#changebackgroundcolor)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### changeBackgroundColor(...)

```typescript
changeBackgroundColor(options: { color: string; }) => Promise<void>
```

| Param | Type |
| ------------- | ------------------------------- |
| **`options`** | <code>{ color: string; }</code> |

--------------------

</docgen-api>
17 changes: 17 additions & 0 deletions packages/webview/WebviewBackground.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = 'WebviewBackground'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = package['repository']['url']
s.author = package['author']
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
end
31 changes: 31 additions & 0 deletions packages/webview/dist/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"api": {
"name": "WebviewBackgroundPlugin",
"slug": "webviewbackgroundplugin",
"docs": "",
"tags": [],
"methods": [
{
"name": "changeBackgroundColor",
"signature": "(options: { color: string; }) => Promise<void>",
"parameters": [
{
"name": "options",
"docs": "",
"type": "{ color: string; }"
}
],
"returns": "Promise<void>",
"tags": [],
"docs": "",
"complexTypes": [],
"slug": "changebackgroundcolor"
}
],
"properties": []
},
"interfaces": [],
"enums": [],
"typeAliases": [],
"pluginConfigs": []
}
5 changes: 5 additions & 0 deletions packages/webview/dist/esm/definitions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface WebviewBackgroundPlugin {
changeBackgroundColor(options: {
color: string;
}): Promise<void>;
}
2 changes: 2 additions & 0 deletions packages/webview/dist/esm/definitions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/webview/dist/esm/definitions.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/webview/dist/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { WebviewBackgroundPlugin } from './definitions';
declare const WebviewBackground: WebviewBackgroundPlugin;
export * from './definitions';
export { WebviewBackground };
7 changes: 7 additions & 0 deletions packages/webview/dist/esm/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/webview/dist/esm/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/webview/dist/esm/web.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { WebPlugin } from '@capacitor/core';
import type { WebviewBackgroundPlugin } from './definitions';
export declare class WebviewBackgroundWeb extends WebPlugin implements WebviewBackgroundPlugin {
changeBackgroundColor(options: {
color: string;
}): Promise<void>;
}
6 changes: 6 additions & 0 deletions packages/webview/dist/esm/web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { WebPlugin } from '@capacitor/core';
export class WebviewBackgroundWeb extends WebPlugin {
async changeBackgroundColor(options) {
console.log('Color changed: ', options.color);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this log was removed as requested from the source (packages/webview/src/web.ts) but then not rebuilt and included in the build here.

One example of why we should build from source rather than including the dist in the repo :)

}
}
1 change: 1 addition & 0 deletions packages/webview/dist/esm/web.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/webview/ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation
import Capacitor

/**
* Please read the Capacitor iOS Plugin Development Guide
* here: https://capacitorjs.com/docs/plugins/ios
*/
@objc(WebviewBackgroundPlugin)
public class WebviewBackgroundPlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "WebviewBackgroundPlugin"
public let jsName = "WebviewBackground"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "changeBackgroundColor", returnType: CAPPluginReturnPromise)
]

@objc func changeBackgroundColor(_ call: CAPPluginCall) {
let color = call.getString("color") ?? ""

self.webView?.backgroundColor = UIColor(named: color)
self.webView?.scrollView.backgroundColor = UIColor(named: color)
}
}
Loading
Loading