file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
playgrounds/preact-js/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + Preact</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.jsx"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-js/src/app.css
CSS
#app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } .logo { height: 6em; padding: 1.5em; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.preact:hover { filter: drop-shadow(0 0 2em #673ab8aa); } .card { padding: 2em; } .read-the-docs { color: #888; }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-js/src/app.jsx
JavaScript (JSX)
import { useState } from "preact/hooks"; import viteLogo from "/vite.svg"; import preactLogo from "./assets/preact.svg"; import "./app.css"; export function App() { const [count, setCount] = useState(0); console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); return ( <> <div> <a href="https://vitejs.dev" target="_blank"> <img src={viteLogo} class="logo" alt="Vite logo" /> </a> <a href="https://preactjs.com" target="_blank"> <img src={preactLogo} class="logo preact" alt="Preact logo" /> </a> </div> <h1>Vite + Preact</h1> <div class="card"> <button onClick={() => setCount((count) => count + 1)}> count is {count} </button> <p> Edit <code>src/app.jsx</code> and save to test HMR </p> </div> <p class="read-the-docs"> Click on the Vite and Preact logos to learn more </p> </> ); }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-js/src/index.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-js/src/main.jsx
JavaScript (JSX)
import { render } from 'preact' import { App } from './app' import './index.css' render(<App />, document.getElementById('app'))
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-js/vite.config.js
JavaScript
import { defineConfig } from 'vite' import preact from '@preact/preset-vite' import removeConsole from 'vite-plugin-remove-console' // https://vitejs.dev/config/ export default defineConfig({ plugins: [preact(), removeConsole()], build: { sourcemap: true } })
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + Preact + TS</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.tsx"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/src/app.css
CSS
#app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } .logo { height: 6em; padding: 1.5em; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.preact:hover { filter: drop-shadow(0 0 2em #673ab8aa); } .card { padding: 2em; } .read-the-docs { color: #888; }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/src/app.tsx
TypeScript (TSX)
import { useState } from "preact/hooks"; import viteLogo from "/vite.svg"; import preactLogo from "./assets/preact.svg"; import "./app.css"; export function App() { const [count, setCount] = useState(0); console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); return ( <> <div> <a href="https://vitejs.dev" target="_blank"> <img src={viteLogo} class="logo" alt="Vite logo" /> </a> <a href="https://preactjs.com" target="_blank"> <img src={preactLogo} class="logo preact" alt="Preact logo" /> </a> </div> <h1>Vite + Preact</h1> <div class="card"> <button onClick={() => setCount((count) => count + 1)}> count is {count} </button> <p> Edit <code>src/app.tsx</code> and save to test HMR </p> </div> <p class="read-the-docs"> Click on the Vite and Preact logos to learn more </p> </> ); }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/src/index.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/src/main.tsx
TypeScript (TSX)
import { render } from 'preact' import { App } from './app' import './index.css' render(<App />, document.getElementById('app') as HTMLElement)
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/src/preact.d.ts
TypeScript
import JSX = preact.JSX
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/src/vite-env.d.ts
TypeScript
/// <reference types="vite/client" />
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/preact-ts/vite.config.ts
TypeScript
import { defineConfig } from "vite"; import preact from "@preact/preset-vite"; import removeConsole from "vite-plugin-remove-console"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [preact(), removeConsole()], build: { sourcemap: true } });
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-js/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + React</title> </head> <body> <div id="root"></div> <script type="module" src="/src/main.jsx"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-js/src/App.css
CSS
#root { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } .logo { height: 6em; padding: 1.5em; will-change: filter; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.react:hover { filter: drop-shadow(0 0 2em #61dafbaa); } @keyframes logo-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } @media (prefers-reduced-motion: no-preference) { a:nth-of-type(2) .logo { animation: logo-spin infinite 20s linear; } } .card { padding: 2em; } .read-the-docs { color: #888; }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-js/src/App.jsx
JavaScript (JSX)
import { useState } from "react"; import viteLogo from "/vite.svg"; import reactLogo from "./assets/react.svg"; import "./App.css"; function App() { const [count, setCount] = useState(0); console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); return ( <div className="App"> <div> <a href="https://vitejs.dev" target="_blank"> <img src={viteLogo} className="logo" alt="Vite logo" /> </a> <a href="https://reactjs.org" target="_blank"> <img src={reactLogo} className="logo react" alt="React logo" /> </a> </div> <h1>Vite + React</h1> <div className="card"> <button onClick={() => setCount((count) => count + 1)}> count is {count} </button> <p> Edit <code>src/App.jsx</code> and save to test HMR </p> </div> <p className="read-the-docs"> Click on the Vite and React logos to learn more </p> </div> ); } export default App;
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-js/src/index.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-js/src/main.jsx
JavaScript (JSX)
import React from 'react' import ReactDOM from 'react-dom/client' import App from './App' import './index.css' ReactDOM.createRoot(document.getElementById('root')).render( <React.StrictMode> <App /> </React.StrictMode> )
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-js/vite.config.js
JavaScript
import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import removeConsole from 'vite-plugin-remove-console' // https://vitejs.dev/config/ export default defineConfig({ plugins: [react(), removeConsole()], build: { sourcemap: true } })
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-ts/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + React + TS</title> </head> <body> <div id="root"></div> <script type="module" src="/src/main.tsx"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-ts/src/App.css
CSS
#root { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } .logo { height: 6em; padding: 1.5em; will-change: filter; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.react:hover { filter: drop-shadow(0 0 2em #61dafbaa); } @keyframes logo-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } @media (prefers-reduced-motion: no-preference) { a:nth-of-type(2) .logo { animation: logo-spin infinite 20s linear; } } .card { padding: 2em; } .read-the-docs { color: #888; }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-ts/src/App.tsx
TypeScript (TSX)
import { useState } from "react"; import viteLogo from "/vite.svg"; import reactLogo from "./assets/react.svg"; import "./App.css"; function App() { const [count, setCount] = useState(0); console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); return ( <div className="App"> <div> <a href="https://vitejs.dev" target="_blank"> <img src={viteLogo} className="logo" alt="Vite logo" /> </a> <a href="https://reactjs.org" target="_blank"> <img src={reactLogo} className="logo react" alt="React logo" /> </a> </div> <h1>Vite + React</h1> <div className="card"> <button onClick={() => setCount((count) => count + 1)}> count is {count} </button> <p> Edit <code>src/App.tsx</code> and save to test HMR </p> </div> <p className="read-the-docs"> Click on the Vite and React logos to learn more </p> </div> ); } export default App;
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-ts/src/index.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-ts/src/main.tsx
TypeScript (TSX)
import React from 'react' import ReactDOM from 'react-dom/client' import App from './App' import './index.css' ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( <React.StrictMode> <App /> </React.StrictMode> )
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-ts/src/vite-env.d.ts
TypeScript
/// <reference types="vite/client" />
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/react-ts/vite.config.ts
TypeScript
import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import removeConsole from "vite-plugin-remove-console"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react(), removeConsole()], build: { sourcemap: true } });
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-js/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="theme-color" content="#000000" /> <link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico" /> <title>Solid App</title> </head> <body> <noscript>You need to enable JavaScript to run this app.</noscript> <div id="root"></div> <script src="/src/index.jsx" type="module"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-js/src/App.jsx
JavaScript (JSX)
import logo from "./logo.svg"; import styles from "./App.module.css"; function App() { function click() { console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); } return ( <div class={styles.App}> <header class={styles.header}> <img src={logo} class={styles.logo} alt="logo" /> <p> Edit <code>src/App.jsx</code> and save to reload. </p> <button onClick={click}>Test</button> </header> </div> ); } export default App;
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-js/src/App.module.css
CSS
.App { text-align: center; } .logo { animation: logo-spin infinite 20s linear; height: 40vmin; pointer-events: none; } .header { background-color: #282c34; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: calc(10px + 2vmin); color: white; } .link { color: #b318f0; } @keyframes logo-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-js/src/index.css
CSS
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } code { font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-js/src/index.jsx
JavaScript (JSX)
/* @refresh reload */ import { render } from 'solid-js/web'; import './index.css'; import App from './App'; render(() => <App />, document.getElementById('root'));
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-js/vite.config.js
JavaScript
import { defineConfig } from 'vite' import solidPlugin from 'vite-plugin-solid' import removeConsole from 'vite-plugin-remove-console' export default defineConfig({ plugins: [solidPlugin(), removeConsole()], server: { port: 3000, }, build: { target: 'esnext', sourcemap: true }, })
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-ts/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="theme-color" content="#000000" /> <link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico" /> <title>Solid App</title> </head> <body> <noscript>You need to enable JavaScript to run this app.</noscript> <div id="root"></div> <script src="/src/index.tsx" type="module"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-ts/src/App.module.css
CSS
.App { text-align: center; } .logo { animation: logo-spin infinite 20s linear; height: 40vmin; pointer-events: none; } .header { background-color: #282c34; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: calc(10px + 2vmin); color: white; } .link { color: #b318f0; } @keyframes logo-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-ts/src/App.tsx
TypeScript (TSX)
import type { Component } from "solid-js"; import logo from "./logo.svg"; import styles from "./App.module.css"; const App: Component = () => { function click() { console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); } return ( <div class={styles.App}> <header class={styles.header}> <img src={logo} class={styles.logo} alt="logo" /> <p> Edit <code>src/App.tsx</code> and save to reload. </p> <button onClick={click}>Test</button> </header> </div> ); }; export default App;
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-ts/src/index.css
CSS
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } code { font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-ts/src/index.tsx
TypeScript (TSX)
/* @refresh reload */ import { render } from 'solid-js/web'; import './index.css'; import App from './App'; render(() => <App />, document.getElementById('root') as HTMLElement);
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/solid-ts/vite.config.ts
TypeScript
import { defineConfig } from "vite"; import solidPlugin from "vite-plugin-solid"; import removeConsole from "vite-plugin-remove-console"; export default defineConfig({ plugins: [solidPlugin(), removeConsole()], server: { port: 3000 }, build: { target: "esnext", sourcemap: true } });
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-js/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + Svelte</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.js"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-js/src/App.svelte
Svelte
<script> import viteLogo from '/vite.svg' import svelteLogo from './assets/svelte.svg' import Counter from './lib/Counter.svelte' </script> <main> <div> <a href="https://vitejs.dev" target="_blank"> <img src={viteLogo} class="logo" alt="Vite Logo" /> </a> <a href="https://svelte.dev" target="_blank"> <img src={svelteLogo} class="logo svelte" alt="Svelte Logo" /> </a> </div> <h1>Vite + Svelte</h1> <div class="card"> <Counter /> </div> <p> Check out <a href="https://github.com/sveltejs/kit#readme" target="_blank">SvelteKit</a>, the official Svelte app framework powered by Vite! </p> <p class="read-the-docs"> Click on the Vite and Svelte logos to learn more </p> </main> <style> .logo { height: 6em; padding: 1.5em; will-change: filter; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.svelte:hover { filter: drop-shadow(0 0 2em #ff3e00aa); } .read-the-docs { color: #888; } </style>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-js/src/app.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } .card { padding: 2em; } #app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-js/src/lib/Counter.svelte
Svelte
<script> console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); let count = 0 const increment = () => { count += 1 console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); } </script> <button on:click={increment}> count is {count} </button>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-js/src/main.js
JavaScript
import './app.css' import App from './App.svelte' const app = new App({ target: document.getElementById('app') }) export default app
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-js/src/vite-env.d.ts
TypeScript
/// <reference types="svelte" /> /// <reference types="vite/client" />
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-js/vite.config.js
JavaScript
import { defineConfig } from 'vite' import { svelte } from '@sveltejs/vite-plugin-svelte' import removeConsole from 'vite-plugin-remove-console' // https://vitejs.dev/config/ export default defineConfig({ plugins: [svelte(), removeConsole()], build: { sourcemap: true } })
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + Svelte + TS</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.ts"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/src/App.svelte
Svelte
<script lang="ts"> import viteLogo from '/vite.svg' import svelteLogo from './assets/svelte.svg' import Counter from './lib/Counter.svelte' </script> <main> <div> <a href="https://vitejs.dev" target="_blank"> <img src={viteLogo} class="logo" alt="Vite Logo" /> </a> <a href="https://svelte.dev" target="_blank"> <img src={svelteLogo} class="logo svelte" alt="Svelte Logo" /> </a> </div> <h1>Vite + Svelte</h1> <div class="card"> <Counter /> </div> <p> Check out <a href="https://github.com/sveltejs/kit#readme" target="_blank">SvelteKit</a>, the official Svelte app framework powered by Vite! </p> <p class="read-the-docs"> Click on the Vite and Svelte logos to learn more </p> </main> <style> .logo { height: 6em; padding: 1.5em; will-change: filter; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.svelte:hover { filter: drop-shadow(0 0 2em #ff3e00aa); } .read-the-docs { color: #888; } </style>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/src/app.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } .card { padding: 2em; } #app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/src/lib/Counter.svelte
Svelte
<script lang="ts"> console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); let count = 0 const increment = () => { count += 1 console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ); } </script> <button on:click={increment}> count is {count} </button>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/src/main.ts
TypeScript
import './app.css' import App from './App.svelte' const app = new App({ target: document.getElementById('app') }) export default app
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/src/vite-env.d.ts
TypeScript
/// <reference types="svelte" /> /// <reference types="vite/client" />
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/svelte.config.js
JavaScript
import sveltePreprocess from 'svelte-preprocess' export default { // Consult https://github.com/sveltejs/svelte-preprocess // for more information about preprocessors preprocess: sveltePreprocess() }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/svelte-ts/vite.config.ts
TypeScript
import { defineConfig } from "vite"; import { svelte } from "@sveltejs/vite-plugin-svelte"; import removeConsole from "vite-plugin-remove-console"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [svelte(), removeConsole()], build: { sourcemap: true } });
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-js/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + Vue</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.js"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-js/src/App.vue
Vue
<script setup> // This starter template is using Vue 3 <script setup> SFCs // Check out https://vuejs.org/api/sfc-script-setup.html#script-setup import HelloWorld from './components/HelloWorld.vue' </script> <template> <div> <a href="https://vitejs.dev" target="_blank"> <img src="/vite.svg" class="logo" alt="Vite logo" /> </a> <a href="https://vuejs.org/" target="_blank"> <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" /> </a> </div> <HelloWorld msg="Vite + Vue" /> </template> <style scoped> .logo { height: 6em; padding: 1.5em; will-change: filter; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.vue:hover { filter: drop-shadow(0 0 2em #42b883aa); } </style>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-js/src/components/HelloWorld.vue
Vue
<script setup> import { ref } from "vue" defineProps({ msg: String }) const count = ref(0) function onClick() { count.value++ console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ) } console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ) </script> <template> <h1>{{ msg }}</h1> <div class="card"> <button type="button" @click="onClick">count is {{ count }}</button> <p> Edit <code>components/HelloWorld.vue</code> to test HMR </p> </div> <p> Check out <a href="https://vuejs.org/guide/quick-start.html#local" target="_blank">create-vue</a>, the official Vue + Vite starter </p> <p> Install <a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a> in your IDE for a better DX </p> <p class="read-the-docs">Click on the Vite and Vue logos to learn more</p> </template> <style scoped> .read-the-docs { color: #888; } </style>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-js/src/main.js
JavaScript
import { createApp } from 'vue' import './style.css' import App from './App.vue' createApp(App).mount('#app')
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-js/src/style.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } .card { padding: 2em; } #app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-js/vite.config.js
JavaScript
import { defineConfig } from "vite" import vue from "@vitejs/plugin-vue" import removeConsole from "vite-plugin-remove-console" // https://vitejs.dev/config/ export default defineConfig({ plugins: [ vue(), removeConsole() ], build: { sourcemap: true } })
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-ts/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vite + Vue + TS</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.ts"></script> </body> </html>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-ts/src/App.vue
Vue
<script setup lang="ts"> // This starter template is using Vue 3 <script setup> SFCs // Check out https://vuejs.org/api/sfc-script-setup.html#script-setup import HelloWorld from './components/HelloWorld.vue' </script> <template> <div> <a href="https://vitejs.dev" target="_blank"> <img src="/vite.svg" class="logo" alt="Vite logo" /> </a> <a href="https://vuejs.org/" target="_blank"> <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" /> </a> </div> <HelloWorld msg="Vite + Vue" /> </template> <style scoped> .logo { height: 6em; padding: 1.5em; will-change: filter; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.vue:hover { filter: drop-shadow(0 0 2em #42b883aa); } </style>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-ts/src/components/HelloWorld.vue
Vue
<script setup lang="ts"> import { ref } from "vue" defineProps<{ msg: string }>() const count = ref(0) function onClick() { debugger count.value++ console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ) } console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console Log Test" ) console.warn( "%cConsole warn Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console warn Test" ) console.error( "%cConsole error Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console error Test" ) console.info( "%cConsole info Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "Console info Test" ) console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "这个不删" ) console.log( "%cConsole Log Test===>>>: ", "color: MidnightBlue; background: Aquamarine; font-size: 20px;", "noRemove" ) let _ = new Promise((_, reject) => { reject(new Error("wrong")) }).then(() => { }).catch(err => { console.log(err) }) // Just testing, not recommended let val = ref(1) val.value = 6 val.value = 8 </script> <template> <h1>{{ msg }}</h1> <div class="card"> <button type="button" @click="onClick">count is {{ count }}</button> <h1>{{ val }}</h1> </div> </template> <style scoped> .read-the-docs { color: #888; } </style>
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-ts/src/env.d.ts
TypeScript
/// <reference types="vite/client" /> declare module '*.vue' { import type { DefineComponent } from 'vue' // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types const component: DefineComponent<{}, {}, any> export default component }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-ts/src/main.ts
TypeScript
import { createApp } from 'vue' import './style.css' import App from './App.vue' createApp(App).mount('#app')
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-ts/src/style.css
CSS
:root { font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } .card { padding: 2em; } #app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
playgrounds/vue-ts/vite.config.ts
TypeScript
import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import removeConsole from "vite-plugin-remove-console"; // import removeConsole from "../../dist/index.mjs"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [ vue(), removeConsole({ includes: ["log", "warn", "error", "info"], externalValue: ["这个不删", "noRemove"], // Completely customize the statements that need to be removed, which will overwrite `includes` custom: [ "debugger", "console.log()", // "console.warn()", // "console.error()", // "console.info()", "val.value = 8" ] }) ], build: { sourcemap: true } });
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
src/index.ts
TypeScript
import { Options } from "./types"; import type { PluginOption } from "vite"; import { transforms, getAbsolutePath } from "./utils"; /** https://github.com/xiaoxian521/vite-plugin-remove-console#-configurable */ export default function removeConsole( options: Partial<Options> = {} ): PluginOption { const { external, includes, externalValue, custom } = options || {}; return { name: "vite:remove-console", apply: "build", enforce: "post", transform(_source: string, id: string) { if (/node_modules/.test(id)) return { code: _source, map: null }; let reg = /(\.vue|\.svelte|\.[jt]sx?)$/.test(id); if ( external && external.length > 0 && getAbsolutePath(external).includes(id) && reg ) { return { code: _source, map: null }; } else { return { code: transforms(_source, includes, externalValue, custom), map: null }; } } }; } export type { PluginOption };
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
src/types.ts
TypeScript
export interface Options { /** The types of console that needs to be removed, such as `log`、`warn`、`error`、`info`, default `log` */ includes?: string[] | undefined; /** Don't remove the types of console these modules */ external?: string[] | undefined; /** Don't remove the log that contains this value */ externalValue?: string[] | undefined; /** Completely customize the statements that need to be removed, which will overwrite `includes` */ custom?: string[] | undefined; }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
src/utils.ts
TypeScript
import { resolve } from "path"; // @ts-expect-error import $T from "./transform"; /** * @description Find console types from ast syntax tree and remove * @param source SourceMap * @returns source after remove console types */ export function transforms( source: string, includes: string[] | undefined, externalValue: string[] | undefined, custom: string[] | undefined ) { let consoles: string[] = []; if (Array.isArray(custom) && custom?.length > 0) { consoles = custom; } else if (includes) { includes?.map(type => { consoles.push(`console.${type}()`); }); } else { consoles = [`console.log()`]; } const findSource = $T(source, { parseOptions: { sourceType: "module" } }).find(consoles); if (externalValue) { return findSource .each((r: any) => { let eValueString = r.value.arguments ?.map((e: { value: string }) => e.value) ?.join(); const pattern = new RegExp(`(${externalValue.join("|")})`, "g"); if (!pattern.test(eValueString)) return r.remove(); }) .root() .generate(); } return findSource.remove().generate(); } /** * @description Get Absolute Path * @param list array of relative paths * @returns Array */ export function getAbsolutePath(list: Array<string>): Array<string> { return list.map(str => { return pathFormat(resolve(process.cwd(), str)); }); } /** * @description translation path(for windows) * @param path string * @returns string */ export function pathFormat(path: string) { const translate = /^\\\\\?\\/.test(path); const hasAscii = /[^\u0000-\u0080]+/.test(path); if (translate || hasAscii) { return path; } return path.replace(/\\/g, "/"); }
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
tsup.config.ts
TypeScript
import { defineConfig } from "tsup"; const config = { outDir: "dist", clean: true, minify: true, sourcemap: false }; export default defineConfig([ { entry: ["src/index.ts"], dts: true, treeshake: true, format: ["esm", "cjs"], ...config } ]);
xiaoxian521/vite-plugin-remove-console
187
Vite plugin that remove all the specified console types in the production environment
TypeScript
xiaoxian521
xiaoming
pure-admin
android/app/build.gradle
Gradle
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.rn_cnnode" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" ndk { abiFilters "armeabi-v7a", "x86" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.0' compile 'com.facebook.react:react-native:0.11.+' }
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
android/app/src/main/java/com/rn_cnnode/MainActivity.java
Java
package com.rn_cnnode; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import com.facebook.react.LifecycleState; import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactRootView; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; import com.facebook.react.shell.MainReactPackage; import com.facebook.soloader.SoLoader; public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { private ReactInstanceManager mReactInstanceManager; private ReactRootView mReactRootView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "RN_CNNode", null); setContentView(mReactRootView); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) { mReactInstanceManager.showDevOptionsDialog(); return true; } return super.onKeyUp(keyCode, event); } @Override public void invokeDefaultOnBackPressed() { super.onBackPressed(); } @Override protected void onPause() { super.onPause(); if (mReactInstanceManager != null) { mReactInstanceManager.onPause(); } } @Override protected void onResume() { super.onResume(); if (mReactInstanceManager != null) { mReactInstanceManager.onResume(this); } } }
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
android/build.gradle
Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenLocal() jcenter() } }
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
android/settings.gradle
Gradle
rootProject.name = 'RN_CNNode' include ':app'
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
commonComponents/Colors.js
JavaScript
const colors = { lineGray: '#F0F0F0', green: '#80BD01', backGray: '#E5E5E5', textGray: '#9A9A9A', textBlack: '#333333', purple: '#9966CC', red: '#f61d4b', backWhite: '#F2F2F2', textGold: '#BC7233', } module.exports = colors;
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
commonComponents/CommonStyles.js
JavaScript
const React = require('react-native'); const Colors = require('./Colors'); const KengHeight = require('./KengComponentHeight'); const { StyleSheet, } = React; const commonStyles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, floorTopName: { height: KengHeight.floorTopNameHeight, backgroundColor: Colors.backWhite, flexDirection: 'row', justifyContent: 'flex-start', }, lineStyle: { width: 3, marginTop: 5, marginBottom: 5, marginLeft: 5, backgroundColor: Colors.red, }, floorTopText: { fontSize: 16, marginLeft: 5, color: Colors.textBlack, alignSelf: 'center', }, bottomLine: { backgroundColor: Colors.backGray, height: KengHeight.floorBottomLineHeight, }, shadowLine: { shadowColor: '#999999', shadowOpacity: 0.8, shadowRadius: 1, shadowOffset: { height: 2, width: 1 }, }, onHighlight: { }, }); module.exports = commonStyles;
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
commonComponents/KengComponentHeight.js
JavaScript
var WindowSize = require('react-native').NativeModules.UIManager.Dimensions.window; const KengComponentHeight = { floorBrandContainerHeight: WindowSize.width * 0.4 + 40, floorTopNameHeight: 35, floorBottomDetailHeight: 35, floorBottomLineHeight: 5, floorMidImageHeight: WindowSize.width * 0.4, floorDoubleItemContainerHeight: 280, floorSingleImageHeight: 180, floorSingleItemContainerHeight: 300, } module.exports = KengComponentHeight;
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
config.js
JavaScript
var config = { "apiHost": "https://cnodejs.org/api/v1/", "topicPath": "https://cnodejs.org/topic/", "loadMaxPages": 5, "loadPerPage": 15, "urlScheme": 'https:', } module.exports = config
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
index.android.js
JavaScript
/** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, } = React; var RN_CNNode = React.createClass({ render: function() { return ( <View style={styles.container}> <Text style={styles.welcome}> Welcome to React Native! </Text> <Text style={styles.instructions}> To get started, edit index.android.js </Text> <Text style={styles.instructions}> Shake or press menu button for dev menu </Text> </View> ); } }); var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, }); AppRegistry.registerComponent('RN_CNNode', () => RN_CNNode);
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
index.ios.js
JavaScript
const React = require('react-native'); const Routes = require('./iosComponents/Routes'); const { AppRegistry, StyleSheet, TabBarIOS, Text, View, NavigatorIOS, } = React; const base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAQAAACSR7JhAAADtUlEQVR4Ac3YA2Bj6QLH0XPT1Fzbtm29tW3btm3bfLZtv7e2ObZnms7d8Uw098tuetPzrxv8wiISrtVudrG2JXQZ4VOv+qUfmqCGGl1mqLhoA52oZlb0mrjsnhKpgeUNEs91Z0pd1kvihA3ULGVHiQO2narKSHKkEMulm9VgUyE60s1aWoMQUbpZOWE+kaqs4eLEjdIlZTcFZB0ndc1+lhB1lZrIuk5P2aib1NBpZaL+JaOGIt0ls47SKzLC7CqrlGF6RZ09HGoNy1lYl2aRSWL5GuzqWU1KafRdoRp0iOQEiDzgZPnG6DbldcomadViflnl/cL93tOoVbsOLVM2jylvdWjXolWX1hmfZbGR/wjypDjFLSZIRov09BgYmtUqPQPlQrPapecLgTIy0jMgPKtTeob2zWtrGH3xvjUkPCtNg/tm1rjwrMa+mdUkPd3hWbH0jArPGiU9ufCsNNWFZ40wpwn+62/66R2RUtoso1OB34tnLOcy7YB1fUdc9e0q3yru8PGM773vXsuZ5YIZX+5xmHwHGVvlrGPN6ZSiP1smOsMMde40wKv2VmwPPVXNut4sVpUreZiLBHi0qln/VQeI/LTMYXpsJtFiclUN+5HVZazim+Ky+7sAvxWnvjXrJFneVtLWLyPJu9K3cXLWeOlbMTlrIelbMDlrLenrjEQOtIF+fuI9xRp9ZBFp6+b6WT8RrxEpdK64BuvHgDk+vUy+b5hYk6zfyfs051gRoNO1usU12WWRWL73/MMEy9pMi9qIrR4ZpV16Rrvduxazmy1FSvuFXRkqTnE7m2kdb5U8xGjLw/spRr1uTov4uOgQE+0N/DvFrG/Jt7i/FzwxbA9kDanhf2w+t4V97G8lrT7wc08aA2QNUkuTfW/KimT01wdlfK4yEw030VfT0RtZbzjeMprNq8m8tnSTASrTLti64oBNdpmMQm0eEwvfPwRbUBywG5TzjPCsdwk3IeAXjQblLCoXnDVeoAz6SfJNk5TTzytCNZk/POtTSV40NwOFWzw86wNJRpubpXsn60NJFlHeqlYRbslqZm2jnEZ3qcSKgm0kTli3zZVS7y/iivZTweYXJ26Y+RTbV1zh3hYkgyFGSTKPfRVbRqWWVReaxYeSLarYv1Qqsmh1s95S7G+eEWK0f3jYKTbV6bOwepjfhtafsvUsqrQvrGC8YhmnO9cSCk3yuY984F1vesdHYhWJ5FvASlacshUsajFt2mUM9pqzvKGcyNJW0arTKN1GGGzQlH0tXwLDgQTurS8eIQAAAABJRU5ErkJggg=='; const TABBABIDS = ['home', 'search', 'post', 'message', 'me']; const RootTabBarController = React.createClass({ getInitialState: function() { return { selectedTab: TABBABIDS[0], }; }, render: function() { return ( <TabBarIOS> <TabBarIOS.Item title="首页" icon={{uri: base64Icon, scale: 3}} selected={this.state.selectedTab === TABBABIDS[0]} onPress={() => { this.setState({ selectedTab: TABBABIDS[0], }); }}> <NavigatorIOS style={{flex: 1}} initialRoute={Routes.allTopics()}/> </TabBarIOS.Item> <TabBarIOS.Item title="发现" icon={{uri: base64Icon, scale: 3}} selected={this.state.selectedTab === TABBABIDS[1]} onPress={() => { this.setState({ selectedTab: TABBABIDS[1], }); }}> <NavigatorIOS style={{flex: 1}} initialRoute={Routes.search()}/> </TabBarIOS.Item> <TabBarIOS.Item title="发帖" icon={{uri: base64Icon, scale: 3}} selected={this.state.selectedTab === TABBABIDS[2]} onPress={() => { this.setState({ selectedTab: TABBABIDS[2], }); }}> <NavigatorIOS style={{flex: 1}} initialRoute={Routes.post()}/> </TabBarIOS.Item> <TabBarIOS.Item title="消息" icon={{uri: base64Icon, scale: 3}} selected={this.state.selectedTab === TABBABIDS[3]} onPress={() => { this.setState({ selectedTab: TABBABIDS[3], }); }}> <NavigatorIOS style={{flex: 1}} initialRoute={Routes.message()}/> </TabBarIOS.Item> <TabBarIOS.Item title="我" icon={{uri: base64Icon, scale: 3}} selected={this.state.selectedTab === TABBABIDS[4]} onPress={() => { this.setState({ selectedTab: TABBABIDS[4], }); }}> <NavigatorIOS style={{flex: 1}} initialRoute={Routes.personal()}/> </TabBarIOS.Item> </TabBarIOS> ); }, }); AppRegistry.registerComponent('RN_CNNode', () => RootTabBarController);
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXCategoryMenuManager.h
C/C++ Header
// // DXNavMenuManager.h // RN_CNNode // // Created by xiekw on 15/10/26. // Copyright © 2015年 Facebook. All rights reserved. // #import "RCTViewManager.h" #import "DXTextCategoryMenu.h" @interface DXCategoryMenuManager : RCTViewManager<DXTextCategoryMenuDelegate> @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXCategoryMenuManager.m
Objective-C
// // DXNavMenuManager.m // RN_CNNode // // Created by xiekw on 15/10/26. // Copyright © 2015年 Facebook. All rights reserved. // #import "DXCategoryMenuManager.h" #import "RCTUtils.h" #import "RCTEventDispatcher.h" #import "UIView+React.h" #import "RCTBridge.h" #import "RCTSparseArray.h" #import "RCTUIManager.h" @implementation DXCategoryMenuManager RCT_EXPORT_MODULE() RCT_EXPORT_VIEW_PROPERTY(options, NSArray) RCT_EXPORT_VIEW_PROPERTY(lockStartPosition, BOOL) RCT_EXPORT_VIEW_PROPERTY(selectedColor, UIColor) RCT_EXPORT_VIEW_PROPERTY(unSelectedColor, UIColor) RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets) RCT_EXPORT_VIEW_PROPERTY(spacingBetweenMenu, CGFloat) RCT_EXPORT_VIEW_PROPERTY(bottomLineHeight, CGFloat) RCT_EXPORT_VIEW_PROPERTY(selectedAnimationDuration, CGFloat) RCT_EXPORT_VIEW_PROPERTY(needCenterMenuOffset, BOOL) RCT_EXPORT_VIEW_PROPERTY(blur, BOOL) RCT_EXPORT_VIEW_PROPERTY(blurEffectStyle, NSInteger) RCT_EXPORT_METHOD(updateSelectedIndex:(nonnull NSNumber *)reactTag selectedIndex:(nonnull NSNumber *)selectedIndex) { [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { DXTextCategoryMenu *view = viewRegistry[reactTag]; if (![view isKindOfClass:[DXTextCategoryMenu class]]) { RCTLogError(@"Invalid view returned from registry, expecting DXTextCategoryMenu, got: %@", view); } else { [view updateSelectedIndex:selectedIndex.integerValue]; } }]; } - (UIView *)view { DXTextCategoryMenu *menu = [[DXTextCategoryMenu alloc] init]; menu.delegate = self; return menu; } - (void)textCategoryMenu:(DXTextCategoryMenu *)menu willSelectedMenuFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)index { NSDictionary *event = @{ @"target": menu.reactTag, @"from": @(fromIndex), @"to": @(index) }; [self.bridge.eventDispatcher sendInputEventWithName:@"topChange" body:event]; } - (void)textCategoryMenu:(DXTextCategoryMenu *)menu didSelectedMenuFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)index { } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXPopover.h
C/C++ Header
// // DXPopover.h // // Created by xiekw on 11/14/14. // Copyright (c) 2014 xiekw. All rights reserved. // #import <UIKit/UIKit.h> typedef NS_ENUM(NSUInteger, DXPopoverPosition) { DXPopoverPositionUp = 1, DXPopoverPositionDown, }; typedef NS_ENUM(NSUInteger, DXPopoverMaskType) { DXPopoverMaskTypeBlack, DXPopoverMaskTypeNone, // overlay does not respond to touch }; @interface DXPopover : UIView + (instancetype)popover; /** * The contentView positioned in container, default is zero; */ @property (nonatomic, assign) UIEdgeInsets contentInset; /** * If the popover is stay up or down the showPoint */ @property (nonatomic, assign, readonly) DXPopoverPosition popoverPosition; /** * The popover arrow size, default is {10.0, 10.0}; */ @property (nonatomic, assign) CGSize arrowSize; /** * The popover corner radius, default is 7.0; */ @property (nonatomic, assign) CGFloat cornerRadius; /** * The popover animation show in duration, default is 0.4; */ @property (nonatomic, assign) CGFloat animationIn; /** * The popover animation dismiss duration, default is 0.3; */ @property (nonatomic, assign) CGFloat animationOut; /** * If the drop in animation using spring animation, default is YES; */ @property (nonatomic, assign) BOOL animationSpring; /** * The background of the popover, default is DXPopoverMaskTypeBlack; */ @property (nonatomic, assign) DXPopoverMaskType maskType; /** * If maskType does not satisfy your need, use blackoverylay to control the touch * event(userInterfaceEnabled) for * background color */ @property (nonatomic, strong, readonly) UIControl *blackOverlay; /** * If the popover has the shadow behind it, default is YES, if you wanna custom the shadow, set it * by * popover.layer.shadowColor, shadowOffset, shadowOpacity, shadowRadius */ @property (nonatomic, assign) BOOL applyShadow; /** * when you using atView show API, this value will be used as the distance between popovers'arrow * and atView. Note: * this value is invalid when popover show using the atPoint API */ @property (nonatomic, assign) CGFloat betweenAtViewAndArrowHeight; /** * Decide the nearest edge between the containerView's border and popover, default is 4.0 */ @property (nonatomic, assign) CGFloat sideEdge; /** * The callback when popover did show in the containerView */ @property (nonatomic, copy) dispatch_block_t didShowHandler; /** * The callback when popover did dismiss in the containerView; */ @property (nonatomic, copy) dispatch_block_t didDismissHandler; /** * Show API * * @param point the point in the container coordinator system. * @param position stay up or stay down from the showAtPoint * @param contentView the contentView to show * @param containerView the containerView to contain */ - (void)showAtPoint:(CGPoint)point popoverPostion:(DXPopoverPosition)position withContentView:(UIView *)contentView inView:(UIView *)containerView; /** * Lazy show API The show point will be caluclated for you, try it! * * @param atView The view to show at * @param position stay up or stay down from the atView, if up or down size is not enough for * contentView, then it * will be set correctly auto. * @param contentView the contentView to show * @param containerView the containerView to contain */ - (void)showAtView:(UIView *)atView popoverPostion:(DXPopoverPosition)position withContentView:(UIView *)contentView inView:(UIView *)containerView; /** * Lazy show API The show point and show position will be caluclated for you, try it! * * @param atView The view to show at * @param contentView the contentView to show * @param containerView the containerView to contain */ - (void)showAtView:(UIView *)atView withContentView:(UIView *)contentView inView:(UIView *)containerView; /** * Lazy show API The show point and show position will be caluclated for you, using * application's keyWindow as * containerView, try it! * * @param atView The view to show at * @param contentView the contentView to show */ - (void)showAtView:(UIView *)atView withContentView:(UIView *)contentView; - (void)showAtView:(UIView *)atView withText:(NSAttributedString *)abs; - (void)showAtView:(UIView *)atView withText:(NSAttributedString *)abs inView:(UIView *)container; - (void)dismiss; @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXPopover.m
Objective-C
// // DXPopover.m // // Created by xiekw on 11/14/14. // Copyright (c) 2014 xiekw. All rights reserved. // #import "DXPopover.h" #define DEGREES_TO_RADIANS(degrees) ((3.14159265359 * degrees) / 180) @interface DXPopover () @property (nonatomic, strong, readwrite) UIControl *blackOverlay; @property (nonatomic, weak) UIView *containerView; @property (nonatomic, assign, readwrite) DXPopoverPosition popoverPosition; @property (nonatomic, assign) CGPoint arrowShowPoint; @property (nonatomic, weak) UIView *contentView; @property (nonatomic, assign) CGRect contentViewFrame; @property (nonatomic, strong) UIColor *contentColor; @end @implementation DXPopover { BOOL _isiOS7; BOOL _setNeedsReset; } + (instancetype)popover { return [[DXPopover alloc] init]; } - (instancetype)init { self = [super initWithFrame:CGRectZero]; if (self) { [self commonInit]; } return self; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:CGRectZero]; if (self) { [self commonInit]; } return self; } - (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { [self commonInit]; } return self; } - (void)commonInit { _isiOS7 = ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending); self.arrowSize = CGSizeMake(11.0, 9.0); self.cornerRadius = 5.0; self.backgroundColor = [UIColor whiteColor]; self.animationIn = 0.4; self.animationOut = 0.3; self.animationSpring = YES; self.sideEdge = 10.0; self.maskType = DXPopoverMaskTypeBlack; self.betweenAtViewAndArrowHeight = 4.0; self.applyShadow = YES; } - (void)setBackgroundColor:(UIColor *)backgroundColor { [super setBackgroundColor:[UIColor clearColor]]; self.contentColor = backgroundColor; } - (void)setApplyShadow:(BOOL)applyShadow { _applyShadow = applyShadow; if (_applyShadow) { self.layer.shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.9].CGColor; self.layer.shadowOffset = CGSizeMake(0, 2); self.layer.shadowOpacity = 0.5; self.layer.shadowRadius = 2.0; } else { self.layer.shadowColor = nil; self.layer.shadowOffset = CGSizeMake(0, 0); self.layer.shadowOpacity = 0.0; self.layer.shadowRadius = 0.0; } } - (void)_setup { if (_setNeedsReset == NO) { return; } CGRect frame = self.contentViewFrame; CGFloat frameMidx = self.arrowShowPoint.x - CGRectGetWidth(frame) * 0.5; frame.origin.x = frameMidx; // we don't need the edge now CGFloat sideEdge = 0.0; if (CGRectGetWidth(frame) < CGRectGetWidth(self.containerView.frame)) { sideEdge = self.sideEdge; } // righter the edge CGFloat outerSideEdge = CGRectGetMaxX(frame) - CGRectGetWidth(self.containerView.bounds); if (outerSideEdge > 0) { frame.origin.x -= (outerSideEdge + sideEdge); } else { if (CGRectGetMinX(frame) < 0) { frame.origin.x += ABS(CGRectGetMinX(frame)) + sideEdge; } } self.frame = frame; CGPoint arrowPoint = [self.containerView convertPoint:self.arrowShowPoint toView:self]; CGPoint anchorPoint; switch (self.popoverPosition) { case DXPopoverPositionDown: { frame.origin.y = self.arrowShowPoint.y; anchorPoint = CGPointMake(arrowPoint.x / CGRectGetWidth(frame), 0); } break; case DXPopoverPositionUp: { frame.origin.y = self.arrowShowPoint.y - CGRectGetHeight(frame) - self.arrowSize.height; anchorPoint = CGPointMake(arrowPoint.x / CGRectGetWidth(frame), 1); } break; } CGPoint lastAnchor = self.layer.anchorPoint; self.layer.anchorPoint = anchorPoint; self.layer.position = CGPointMake( self.layer.position.x + (anchorPoint.x - lastAnchor.x) * self.layer.bounds.size.width, self.layer.position.y + (anchorPoint.y - lastAnchor.y) * self.layer.bounds.size.height); frame.size.height += self.arrowSize.height; self.frame = frame; _setNeedsReset = NO; } - (void)showAtPoint:(CGPoint)point popoverPostion:(DXPopoverPosition)position withContentView:(UIView *)contentView inView:(UIView *)containerView { CGFloat contentWidth = CGRectGetWidth(contentView.bounds); CGFloat contentHeight = CGRectGetHeight(contentView.bounds); CGFloat containerWidth = CGRectGetWidth(containerView.bounds); CGFloat containerHeight = CGRectGetHeight(containerView.bounds); NSAssert(contentWidth > 0 && contentHeight > 0, @"DXPopover contentView bounds.size should not be zero"); NSAssert(containerWidth > 0 && containerHeight > 0, @"DXPopover containerView bounds.size should not be zero"); NSAssert(containerWidth >= (contentWidth + self.contentInset.left + self.contentInset.right), @"DXPopover containerView width %f should be wider than contentViewWidth %f & " @"contentInset %@", containerWidth, contentWidth, NSStringFromUIEdgeInsets(self.contentInset)); if (!self.blackOverlay) { self.blackOverlay = [[UIControl alloc] init]; self.blackOverlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } self.blackOverlay.frame = containerView.bounds; UIColor *maskColor; switch (self.maskType) { case DXPopoverMaskTypeBlack: maskColor = [UIColor colorWithWhite:0.0 alpha:0.3]; break; case DXPopoverMaskTypeNone: { maskColor = [UIColor clearColor]; self.blackOverlay.userInteractionEnabled = NO; } break; default: break; } self.blackOverlay.backgroundColor = maskColor; [containerView addSubview:self.blackOverlay]; [self.blackOverlay addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; self.containerView = containerView; self.contentView = contentView; self.popoverPosition = position; self.arrowShowPoint = point; CGRect contentFrame = [containerView convertRect:contentView.frame toView:containerView]; BOOL isEdgeZero = UIEdgeInsetsEqualToEdgeInsets(self.contentInset, UIEdgeInsetsZero); // if the edgeInset is not be setted, we use need set the contentViews cornerRadius if (isEdgeZero) { self.contentView.layer.cornerRadius = self.cornerRadius; self.contentView.layer.masksToBounds = YES; } else { contentFrame.size.width += self.contentInset.left + self.contentInset.right; contentFrame.size.height += self.contentInset.top + self.contentInset.bottom; } self.contentViewFrame = contentFrame; [self show]; } - (void)showAtView:(UIView *)atView popoverPostion:(DXPopoverPosition)position withContentView:(UIView *)contentView inView:(UIView *)containerView { CGFloat betweenArrowAndAtView = self.betweenAtViewAndArrowHeight; CGFloat contentViewHeight = CGRectGetHeight(contentView.bounds); CGRect atViewFrame = [containerView convertRect:atView.frame toView:containerView]; BOOL upCanContain = CGRectGetMinY(atViewFrame) >= contentViewHeight + betweenArrowAndAtView; BOOL downCanContain = (CGRectGetHeight(containerView.bounds) - (CGRectGetMaxY(atViewFrame) + betweenArrowAndAtView)) >= contentViewHeight; NSAssert((upCanContain || downCanContain), @"DXPopover no place for the popover show, check atView frame %@ " @"check contentView bounds %@ and containerView's bounds %@", NSStringFromCGRect(atViewFrame), NSStringFromCGRect(contentView.bounds), NSStringFromCGRect(containerView.bounds)); CGPoint atPoint = CGPointMake(CGRectGetMidX(atViewFrame), 0); DXPopoverPosition popoverPosition; if (upCanContain) { popoverPosition = DXPopoverPositionUp; atPoint.y = CGRectGetMinY(atViewFrame) - betweenArrowAndAtView; } else { popoverPosition = DXPopoverPositionDown; atPoint.y = CGRectGetMaxY(atViewFrame) + betweenArrowAndAtView; } // if they are all yes then it shows in the bigger container if (upCanContain && downCanContain) { CGFloat upHeight = CGRectGetMinY(atViewFrame); CGFloat downHeight = CGRectGetHeight(containerView.bounds) - CGRectGetMaxY(atViewFrame); BOOL useUp = upHeight > downHeight; // except you set outsider if (position != 0) { useUp = position == DXPopoverPositionUp ? YES : NO; } if (useUp) { popoverPosition = DXPopoverPositionUp; atPoint.y = CGRectGetMinY(atViewFrame) - betweenArrowAndAtView; } else { popoverPosition = DXPopoverPositionDown; atPoint.y = CGRectGetMaxY(atViewFrame) + betweenArrowAndAtView; } } [self showAtPoint:atPoint popoverPostion:popoverPosition withContentView:contentView inView:containerView]; } - (void)showAtView:(UIView *)atView withContentView:(UIView *)contentView inView:(UIView *)containerView { [self showAtView:atView popoverPostion:0 withContentView:contentView inView:containerView]; } - (void)showAtView:(UIView *)atView withContentView:(UIView *)contentView { [self showAtView:atView withContentView:contentView inView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; } - (void)show { _setNeedsReset = YES; [self setNeedsDisplay]; CGRect contentViewFrame = self.contentView.frame; CGFloat originY = 0.0; if (self.popoverPosition == DXPopoverPositionDown) { originY = self.arrowSize.height; } contentViewFrame.origin.x = self.contentInset.left; contentViewFrame.origin.y = originY + self.contentInset.top; self.contentView.frame = contentViewFrame; [self addSubview:self.contentView]; [self.containerView addSubview:self]; self.transform = CGAffineTransformMakeScale(0.0, 0.0); if (self.animationSpring && _isiOS7) { [UIView animateWithDuration:self.animationIn delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:3 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { if (self.didShowHandler) { self.didShowHandler(); } }]; } else { [UIView animateWithDuration:self.animationIn delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { if (self.didShowHandler) { self.didShowHandler(); } }]; } } - (void)showAtView:(UIView *)atView withText:(NSAttributedString *)abs { [self showAtView:atView withText:abs inView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; } - (void)showAtView:(UIView *)atView withText:(NSAttributedString *)abs inView:(UIView *)container { UILabel *textLabel = [UILabel new]; textLabel.attributedText = abs; [textLabel sizeToFit]; textLabel.backgroundColor = [UIColor clearColor]; self.contentInset = UIEdgeInsetsMake(3.0, 3.0, 3.0, 3.0); [self showAtView:atView withContentView:textLabel inView:container]; } - (void)dismiss { if (self.superview) { [UIView animateWithDuration:self.animationOut delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{ self.transform = CGAffineTransformMakeScale(0.0001, 0.0001); } completion:^(BOOL finished) { [self.contentView removeFromSuperview]; [self.blackOverlay removeFromSuperview]; [self removeFromSuperview]; if (self.didDismissHandler) { self.didDismissHandler(); } }]; } } - (void)drawRect:(CGRect)rect { UIBezierPath *arrow = [[UIBezierPath alloc] init]; UIColor *contentColor = self.contentColor; // the point in the ourself view coordinator CGPoint arrowPoint = [self.containerView convertPoint:self.arrowShowPoint toView:self]; CGSize arrowSize = self.arrowSize; CGFloat cornerRadius = self.cornerRadius; CGSize size = self.bounds.size; switch (self.popoverPosition) { case DXPopoverPositionDown: { [arrow moveToPoint:CGPointMake(arrowPoint.x, 0)]; [arrow addLineToPoint:CGPointMake(arrowPoint.x + arrowSize.width * 0.5, arrowSize.height)]; [arrow addLineToPoint:CGPointMake(size.width - cornerRadius, arrowSize.height)]; [arrow addArcWithCenter:CGPointMake(size.width - cornerRadius, arrowSize.height + cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(270.0) endAngle:DEGREES_TO_RADIANS(0) clockwise:YES]; [arrow addLineToPoint:CGPointMake(size.width, size.height - cornerRadius)]; [arrow addArcWithCenter:CGPointMake(size.width - cornerRadius, size.height - cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(90.0) clockwise:YES]; [arrow addLineToPoint:CGPointMake(0, size.height)]; [arrow addArcWithCenter:CGPointMake(cornerRadius, size.height - cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(90) endAngle:DEGREES_TO_RADIANS(180.0) clockwise:YES]; [arrow addLineToPoint:CGPointMake(0, arrowSize.height + cornerRadius)]; [arrow addArcWithCenter:CGPointMake(cornerRadius, arrowSize.height + cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(180.0) endAngle:DEGREES_TO_RADIANS(270) clockwise:YES]; [arrow addLineToPoint:CGPointMake(arrowPoint.x - arrowSize.width * 0.5, arrowSize.height)]; } break; case DXPopoverPositionUp: { [arrow moveToPoint:CGPointMake(arrowPoint.x, size.height)]; [arrow addLineToPoint:CGPointMake(arrowPoint.x - arrowSize.width * 0.5, size.height - arrowSize.height)]; [arrow addLineToPoint:CGPointMake(cornerRadius, size.height - arrowSize.height)]; [arrow addArcWithCenter:CGPointMake(cornerRadius, size.height - arrowSize.height - cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(90.0) endAngle:DEGREES_TO_RADIANS(180.0) clockwise:YES]; [arrow addLineToPoint:CGPointMake(0, cornerRadius)]; [arrow addArcWithCenter:CGPointMake(cornerRadius, cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(180.0) endAngle:DEGREES_TO_RADIANS(270.0) clockwise:YES]; [arrow addLineToPoint:CGPointMake(size.width - cornerRadius, 0)]; [arrow addArcWithCenter:CGPointMake(size.width - cornerRadius, cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(270.0) endAngle:DEGREES_TO_RADIANS(0) clockwise:YES]; [arrow addLineToPoint:CGPointMake(size.width, size.height - arrowSize.height - cornerRadius)]; [arrow addArcWithCenter:CGPointMake(size.width - cornerRadius, size.height - arrowSize.height - cornerRadius) radius:cornerRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(90.0) clockwise:YES]; [arrow addLineToPoint:CGPointMake(arrowPoint.x + arrowSize.width * 0.5, size.height - arrowSize.height)]; } break; } [contentColor setFill]; [arrow fill]; } - (void)layoutSubviews { [self _setup]; } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXRefreshControl.h
C/C++ Header
// // DXRefreshControl.h // RN_CNNode // // Created by xiekw on 15/10/20. // Copyright © 2015年 Facebook. All rights reserved. // #import <Foundation/Foundation.h> #import "RCTBridgeModule.h" @interface DXRefreshControl : NSObject<RCTBridgeModule> @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXRefreshControl.m
Objective-C
// // DXRefreshControl.m // RN_CNNode // // Created by xiekw on 15/10/20. // Copyright © 2015年 Facebook. All rights reserved. // #import "DXRefreshControl.h" #import "RCTBridge.h" #import "RCTConvert.h" #import "RCTScrollView.h" #import "RCTSparseArray.h" #import "RCTUIManager.h" #import "RCTEventDispatcher.h" #import "UIView+react.h" #import "JHSPullToRefreshControl.h" #import "JHSMagicLampPullToRefreshView.h" @implementation DXRefreshControl { } @synthesize bridge = _bridge; - (dispatch_queue_t)methodQueue { return _bridge.uiManager.methodQueue; } RCT_EXPORT_MODULE(); /** * config using the custom refresh header and it must be used like UIRefreshControl * * @param config { * headerViewClass: 'JHSPullToRefreshControl', * contentViewClass: 'JHSMagicLampPullToRefreshView' * color: '#AA00FF' * } * */ RCT_EXPORT_METHOD(configureCustom:(nonnull NSNumber *)reactTag headerConfig:(NSDictionary *)config callback:(RCTResponseSenderBlock)callback) { Class headerViewClass = NSClassFromString(config[@"headerViewClass"]); if (!headerViewClass) { NSLog(@"DXRefreshControl can not find refresh header with headerClassName %@", config[@"headerViewClass"]); return; } [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { dispatch_async(dispatch_get_main_queue(), ^{ UIView *view = viewRegistry[reactTag]; if (!view) { NSLog(@"Cannot find view with tag #%@", reactTag); return; } UIScrollView *scrollView = ((RCTScrollView *)view).scrollView; NSInteger refreshTag = reactTag.integerValue; id refreshControl = (Class)[scrollView viewWithTag:refreshTag]; if (!refreshControl) { CGRect f = scrollView.bounds; f.origin.y -= f.size.height; JHSPullToRefreshControl *refreshControl = [[headerViewClass alloc] initWithFrame:f]; Class contentViewClass = NSClassFromString(config[@"contentViewClass"]); if (contentViewClass) { if ([refreshControl respondsToSelector:@selector(view)]) { refreshControl.view = [contentViewClass new]; } } id color = config[@"color"]; if (color) { color = [RCTConvert UIColor:color]; refreshControl.tintColor = color; } [scrollView addSubview:refreshControl]; refreshControl.tag = refreshTag; [refreshControl addTarget:self action:@selector(dropViewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged]; callback(@[[NSNull null], reactTag]); } }); }]; } RCT_EXPORT_METHOD(beginRefreshing:(nonnull NSNumber *)reactTag) { [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { dispatch_async(dispatch_get_main_queue(), ^{ UIView *view = viewRegistry[reactTag]; if (!view) { RCTLogError(@"Cannot find view with tag #%@", reactTag); return; } UIScrollView *scrollView = ((RCTScrollView *)view).scrollView; NSLog(@"scrollView contentinset is %@" , NSStringFromUIEdgeInsets(scrollView.contentInset)) ; UIRefreshControl *refreshControl = (UIRefreshControl *)[scrollView viewWithTag:reactTag.integerValue]; CGFloat contentOffsetY = -(CGRectGetHeight(refreshControl.bounds)) - scrollView.contentInset.top; [scrollView setContentOffset:CGPointMake(0, contentOffsetY) animated:YES]; [refreshControl beginRefreshing]; }); }]; } RCT_EXPORT_METHOD(endRefreshing:(nonnull NSNumber *)reactTag) { [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { dispatch_async(dispatch_get_main_queue(), ^{ UIView *view = viewRegistry[reactTag]; if (!view) { RCTLogError(@"Cannot find view with tag #%@", reactTag); return; } UIScrollView *scrollView = ((RCTScrollView *)view).scrollView; UIRefreshControl *refreshControl = (UIRefreshControl *)[scrollView viewWithTag:reactTag.integerValue]; [refreshControl endRefreshing]; }); }]; } - (void)dropViewDidBeginRefreshing:(UIRefreshControl *)sender { [self.bridge.eventDispatcher sendDeviceEventWithName:@"dropViewDidBeginRefreshing" body:@(sender.tag)]; } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXTopMessageManager.h
C/C++ Header
// // DXTopMessageManager.h // RN_CNNode // // Created by xiekw on 15/10/21. // Copyright © 2015年 Facebook. All rights reserved. // #import <Foundation/Foundation.h> #import "RCTBridgeModule.h" @interface DXTopMessageManager : NSObject<RCTBridgeModule> @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/DXTopMessageManager.m
Objective-C
// // DXTopMessageManager.m // RN_CNNode // // Created by xiekw on 15/10/21. // Copyright © 2015年 Facebook. All rights reserved. // #import "DXTopMessageManager.h" #import "RCTBridge.h" #import "RCTConvert.h" #import "RCTScrollView.h" #import "RCTSparseArray.h" #import "RCTUIManager.h" #import "RCTEventDispatcher.h" #import "UIView+react.h" #import "UIView+TopBarMessage.h" @implementation DXTopMessageManager @synthesize bridge = _bridge; - (dispatch_queue_t)methodQueue { return _bridge.uiManager.methodQueue; } RCT_EXPORT_MODULE(); /** * Show top message * * @param config { * background: '#111111', * textColor: '#111111', * font: {'fontFamily': 'hev', 'fontSize': 12, 'fontWeight': 11, 'fontStyle': 'bold'}, * icon: 'imagename', * offset: 64, * } * */ RCT_EXPORT_METHOD(showTopMessage:(nonnull NSNumber *)reactTag message:(nonnull NSString *)message config:(NSDictionary *)config callback:(RCTResponseSenderBlock)callback) { [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { dispatch_async(dispatch_get_main_queue(), ^{ UIView *view = viewRegistry[reactTag]; if (!view) { NSLog(@"Cannot find view with tag #%@", reactTag); return; } [view showTopMessage:message topBarConfig:[self mapTopBarConfig:config] dismissDelay:3.0 withTapBlock:^{ [_bridge.eventDispatcher sendDeviceEventWithName:@"messageTapped" body:reactTag]; }]; callback(@[[NSNull null], reactTag]); }); }]; } - (NSDictionary *)mapTopBarConfig:(NSDictionary *)jsConfig { NSMutableDictionary *mdic = [NSMutableDictionary dictionaryWithCapacity:jsConfig.count]; id backColor = jsConfig[@"background"]; if (backColor) { mdic[kDXTopBarBackgroundColor] = [RCTConvert UIColor:backColor]; } id textColor = jsConfig[@"textColor"]; if (textColor) { mdic[kDXTopBarTextColor] = [RCTConvert UIColor:textColor]; } id font = jsConfig[@"font"]; if (font) { mdic[kDXTopBarTextFont] = [RCTConvert UIFont:font]; } id offset = jsConfig[@"offset"]; mdic[kDXTopBarOffset] = @([offset floatValue]); return mdic; } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/NavigationCategory/DXTextCategoryMenu.h
C/C++ Header
// // DXTextCategoryMenu.h // RN_CNNode // // Created by xiekw on 15/10/23. // Copyright © 2015年 Facebook. All rights reserved. // #import <UIKit/UIKit.h> @class DXTextCategoryMenu; @protocol DXTextCategoryMenuDelegate <NSObject> @optional - (void)textCategoryMenu:(DXTextCategoryMenu *)menu willSelectedMenuFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)index; - (void)textCategoryMenu:(DXTextCategoryMenu *)menu didSelectedMenuFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)index; @end @interface DXTextCategoryMenu : UIView @property (nonatomic, weak) id<DXTextCategoryMenuDelegate> delegate; @property (nonatomic, strong) NSArray *options; // If the first item stays the position when others scroll @property (nonatomic, assign) BOOL lockStartPosition; // Selected color, default is red @property (nonatomic, strong) UIColor *selectedColor; // UnSelected color, default is lightgray @property (nonatomic, strong) UIColor *unSelectedColor; // The menu contentInset in container. default is {2, 5, 2, 5} @property (nonatomic, assign) UIEdgeInsets contentInset; // Each text menu between space @property (nonatomic, assign) CGFloat spacingBetweenMenu; // The bottom line height, default is 2 @property (nonatomic, assign) CGFloat bottomLineHeight; // The bottom line animation flys default is 0.25 @property (nonatomic, assign) CGFloat selectedAnimationDuration; // The trigger scrollView autoscroll space between the side, default is 100 @property (nonatomic, assign) CGFloat needCenterMenuOffset; // If use the system blur, default is YES @property (nonatomic, assign, getter=isBlur) BOOL blur; // If blur which style to use, defaut is extra light @property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle; - (void)updateSelectedIndex:(NSInteger)index; @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/NavigationCategory/DXTextCategoryMenu.m
Objective-C
// // DXTextCategoryMenu.m // RN_CNNode // // Created by xiekw on 15/10/23. // Copyright © 2015年 Facebook. All rights reserved. // #import "DXTextCategoryMenu.h" #import "UIView+SNEdge.h" #import "RCTConvert.h" @interface _TextButton : UIButton + (instancetype)textButtonWithString:(NSString *)text selectedColor:(UIColor *)sColor unSelectedColor:(UIColor *)uScolor; @end @implementation _TextButton + (instancetype)textButtonWithString:(NSString *)text selectedColor:(UIColor *)sColor unSelectedColor:(UIColor *)uScolor { _TextButton *btn = [_TextButton new]; [btn setTitle:text forState:UIControlStateNormal]; [btn setTitleColor:uScolor forState:UIControlStateNormal]; [btn setTitleColor:sColor forState:UIControlStateSelected]; [btn sizeToFit]; return btn; } - (instancetype)init { if (self = [super init]) { self.backgroundColor = [UIColor clearColor]; } return self; } @end @interface _MenuScrollView : UIScrollView @end @implementation _MenuScrollView - (BOOL)touchesShouldCancelInContentView:(UIView *)view { return YES; } @end @interface DXTextCategoryMenu ()<UIScrollViewDelegate> @property (nonatomic, strong) NSMutableArray *textButtons; @property (nonatomic, assign) NSUInteger selectedIndex; @property (nonatomic, strong) UIView *bottomLine; @property (nonatomic, strong) UIVisualEffectView *blurEffectView; @end @implementation DXTextCategoryMenu { _MenuScrollView *_scrollView; UIButton *_expandButton; struct { unsigned int delegateImpWillSelect: 1; unsigned int delegateImpDidSelect: 1; }_delegateFlags; BOOL _dirty; BOOL _animating; } - (void)_commonInit { _delegateFlags.delegateImpWillSelect = 0; _delegateFlags.delegateImpDidSelect = 0; _dirty = NO; self.blurEffectStyle = UIBlurEffectStyleExtraLight; self.backgroundColor = [UIColor clearColor]; _scrollView = [_MenuScrollView new]; _scrollView.delaysContentTouches = NO; _scrollView.canCancelContentTouches = YES; _scrollView.showsHorizontalScrollIndicator = NO; _scrollView.showsVerticalScrollIndicator = NO; _scrollView.scrollsToTop = NO; _scrollView.delegate = self; _scrollView.frame = self.bounds; [self addSubview:_scrollView]; self.selectedColor = [RCTConvert UIColor:@"#f61d4b"]; self.unSelectedColor = [RCTConvert UIColor:@"#666666"]; self.contentInset = UIEdgeInsetsMake(2.0, 5, 2.0, 5); self.spacingBetweenMenu = 20.0; _selectedIndex = -1; _bottomLineHeight = 2.0; _selectedAnimationDuration = 0.25; _needCenterMenuOffset = 100.0; self.blur = YES; } - (void)_applyShadows { self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath; self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOpacity = 0.17f; self.layer.shadowRadius = 0.5f; self.layer.shadowOffset = CGSizeMake(0, 0.4); } - (void)setDelegate:(id<DXTextCategoryMenuDelegate>)delegate { if (_delegate == delegate) { return; } _delegate = delegate; _delegateFlags.delegateImpWillSelect = [_delegate respondsToSelector:@selector(textCategoryMenu:willSelectedMenuFromIndex:toIndex:)]; _delegateFlags.delegateImpDidSelect = [_delegate respondsToSelector:@selector(textCategoryMenu:didSelectedMenuFromIndex:toIndex:)]; } - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self _commonInit]; } return self; } - (instancetype)init { if (self = [super init]) { [self _commonInit]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; if (_dirty) { _scrollView.frame = self.bounds; _blurEffectView.effect = [UIBlurEffect effectWithStyle:self.blurEffectStyle]; _blurEffectView.frame = self.bounds; [self _applyShadows]; [self _reset]; CGFloat startX = self.contentInset.left; CGFloat height = CGRectGetHeight(_scrollView.bounds); CGFloat previousX = startX; for (NSUInteger i = 0; i < _options.count; i ++) { NSString *option = _options[i]; _TextButton *textButton = [_TextButton textButtonWithString:option selectedColor:self.selectedColor unSelectedColor:self.unSelectedColor]; CGSize textButtonSize = textButton.bounds.size; CGFloat startY = (height - self.contentInset.top - self.contentInset.bottom - textButtonSize.height) * 0.5; textButton.frame = CGRectMake(previousX + i * self.spacingBetweenMenu, startY, textButtonSize.width, textButtonSize.height); textButton.tag = i; [textButton addTarget:self action:@selector(textButtonDidTapped:) forControlEvents:UIControlEventTouchUpInside]; [_scrollView addSubview:textButton]; [self.textButtons addObject:textButton]; previousX += textButtonSize.width; } _scrollView.contentSize = CGSizeMake(previousX + self.spacingBetweenMenu * (_options.count - 1) + self.contentInset.right, height); self.bottomLine.frame = CGRectMake(0, CGRectGetHeight(_scrollView.bounds) - _bottomLineHeight, 0, _bottomLineHeight); [_scrollView addSubview:self.bottomLine]; _selectedIndex = 0; _TextButton *firstBtn = [_textButtons firstObject]; firstBtn.selected = YES; [self _moveBottomLineToSelectedButton]; _dirty = NO; } } - (void)setBlur:(BOOL)blur { if (_blur == blur || ![UIVisualEffect class]) { self.backgroundColor = [UIColor whiteColor]; return; } _blur = blur; if (_blur) { self.backgroundColor = [UIColor clearColor]; self.blurEffectView.frame = self.bounds; [self insertSubview:self.blurEffectView belowSubview:_scrollView]; } else { [self.blurEffectView removeFromSuperview]; self.backgroundColor = [UIColor whiteColor]; } } - (UIVisualEffectView *)blurEffectView { if (!_blurEffectView) { UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:self.blurEffectStyle]; UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; _blurEffectView = visualEffectView; } return _blurEffectView; } - (void)setBlurEffectStyle:(UIBlurEffectStyle)effectStyle { if (_blurEffectStyle == effectStyle) { return; } _blurEffectStyle = effectStyle; _dirty = YES; } - (void)setBackgroundColor:(UIColor *)backgroundColor { if (self.blur || [self.backgroundColor isEqual:backgroundColor]) { return; } [super setBackgroundColor:backgroundColor]; _scrollView.backgroundColor = backgroundColor; } - (void)_reset { [_scrollView removeAllSubviews]; [self.textButtons removeAllObjects]; _selectedIndex = -1; [self.bottomLine removeFromSuperview]; } - (void)setOptions:(NSArray *)options { _options = options; _dirty = YES; } - (void)updateSelectedIndex:(NSInteger)index { [self setSelectedIndex:index notifyDelegate:NO]; } - (void)setSelectedIndex:(NSUInteger)selectedIndex notifyDelegate:(BOOL)notify { if (_selectedIndex == selectedIndex || _animating) { return; } if (selectedIndex >= _options.count) { NSLog(@"*** [DXTextCategoryMenu] selected index is out of range with %lu from %lu", (unsigned long)selectedIndex, (unsigned long)_options.count); return; } NSUInteger orginIndex = _selectedIndex; if (notify && _delegateFlags.delegateImpWillSelect) { [_delegate textCategoryMenu:self willSelectedMenuFromIndex:orginIndex toIndex:selectedIndex]; } _selectedIndex = selectedIndex; [_textButtons enumerateObjectsUsingBlock:^(_TextButton *btn, NSUInteger idx, BOOL * _Nonnull stop) { btn.selected = idx == _selectedIndex; }]; [self _setNeedCenterScrollView]; [self _moveBottomLineToSelectedButton]; if (notify && _delegateFlags.delegateImpDidSelect) { [_delegate textCategoryMenu:self didSelectedMenuFromIndex:orginIndex toIndex:_selectedIndex]; } } - (void)_moveBottomLineToSelectedButton { if (_animating) { return; } _animating = YES; CGRect currentLineBounds = self.bottomLine.bounds; CGPoint targetCenter = self.bottomLine.center; CGRect targetBounds = currentLineBounds; _TextButton *currentBtn = _textButtons[_selectedIndex]; targetCenter.x = currentBtn.center.x; targetBounds.size.width = CGRectGetWidth(currentBtn.bounds); [UIView animateWithDuration:self.selectedAnimationDuration animations:^{ self.bottomLine.center = targetCenter; self.bottomLine.bounds = targetBounds; } completion:^(BOOL finished) { _animating = NO; }]; } - (void)_setNeedCenterScrollView { _TextButton *btn = _textButtons[_selectedIndex]; CGFloat scrollViewWidth = CGRectGetWidth(_scrollView.frame); CGPoint scrollViewContentOffset = _scrollView.contentOffset; CGFloat currentX = btn.center.x - scrollViewContentOffset.x; if (currentX < self.needCenterMenuOffset) { NSUInteger next2 = _selectedIndex + 2; NSUInteger nextButtonIndex = next2 < _options.count - 1 ? next2 : _selectedIndex + 1 ; if (nextButtonIndex > _options.count - 1) { return; } _TextButton *nextBtn = _textButtons[nextButtonIndex]; CGFloat needMoved = nextBtn.center.x - btn.center.x; _TextButton *firstBtn = [_textButtons firstObject]; CGFloat minMove = btn.center.x - firstBtn.center.x; needMoved = MIN(needMoved, minMove); needMoved = scrollViewContentOffset.x - needMoved; if (needMoved <= 0 || firstBtn == btn) { needMoved = 0; } [_scrollView setContentOffset:CGPointMake(needMoved, 0) animated:YES]; } if (scrollViewWidth - currentX < self.needCenterMenuOffset) { NSInteger previous2 = _selectedIndex - 2; NSInteger previousButtonInex = previous2 > 0 ? previous2 : _selectedIndex - 1; if (previousButtonInex < 0) { return; } _TextButton *previousBtn = _textButtons[previousButtonInex]; CGFloat needMoved = previousBtn.center.x - btn.center.x; _TextButton *lastBtn = [_textButtons lastObject]; CGFloat minMove = btn.center.x - lastBtn.center.x; needMoved = MAX(needMoved, minMove); needMoved = scrollViewContentOffset.x - needMoved; if (needMoved >= _scrollView.contentSize.width - scrollViewWidth || lastBtn == btn) { needMoved = _scrollView.contentSize.width - scrollViewWidth; } [_scrollView setContentOffset:CGPointMake(needMoved, 0) animated:YES]; } } - (void)textButtonDidTapped:(_TextButton *)button { NSUInteger tag = button.tag; [self setSelectedIndex:tag notifyDelegate:YES]; } - (void)setSelectedColor:(UIColor *)selectedColor { if ([_selectedColor isEqual:selectedColor]) { return; } _selectedColor = selectedColor; for (_TextButton *btn in self.textButtons) { [btn setTitleColor:_selectedColor forState:UIControlStateSelected]; } self.bottomLine.backgroundColor = _selectedColor; } - (void)setUnSelectedColor:(UIColor *)unSelectedColor { if ([_unSelectedColor isEqual:unSelectedColor]) { return; } _unSelectedColor = unSelectedColor; for (_TextButton *btn in self.textButtons) { [btn setTitleColor:_unSelectedColor forState:UIControlStateNormal]; } } - (UIView *)bottomLine { if (!_bottomLine) { _bottomLine = [[UIView alloc] init]; _bottomLine.backgroundColor = self.selectedColor; } return _bottomLine; } - (void)setBottomLineHeight:(CGFloat)bottomLineHeight { if (_bottomLineHeight == bottomLineHeight) { return; } self.bottomLine.bounds = CGRectMake(0, 0, CGRectGetWidth(self.bottomLine.bounds), _bottomLineHeight); } - (NSMutableArray *)textButtons { if (!_textButtons) { _textButtons = [NSMutableArray array]; } return _textButtons; } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PopoverManager.h
C/C++ Header
// // PopoverManager.h // RN_CNNode // // Created by xiekw on 15/10/20. // Copyright © 2015年 Facebook. All rights reserved. // #import <Foundation/Foundation.h> #import "RCTBridgeModule.h" @interface PopoverManager : NSObject<RCTBridgeModule> @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PopoverManager.m
Objective-C
// // PopoverManager.m // RN_CNNode // // Created by xiekw on 15/10/20. // Copyright © 2015年 Facebook. All rights reserved. // #import "PopoverManager.h" #import "DXPopover.h" @implementation PopoverManager RCT_EXPORT_MODULE(); RCT_EXPORT_METHOD(showAtView:(NSNumber *)atView withText:(NSString *)text) { NSLog(@"hellow js"); DXPopover *popover = [DXPopover popover]; NSAttributedString *abs = [[NSAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont systemFontOfSize:16.0]}]; [popover showAtView:atView withText:abs]; } RCT_EXPORT_METHOD(addEvent:(NSString *)atView location:(NSString *)text) { NSLog(@"hellow js %@ %@", atView, text); } - (dispatch_queue_t)methodQueue { return dispatch_get_main_queue(); } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PullToRefresh/JHSCartoonPullToRefreshView.h
C/C++ Header
// // JHSCartoonPullToRefreshView.h // JU // // Created by lamo on 14/12/23. // Copyright (c) 2014年 ju.taobao.com. All rights reserved. // #import <UIKit/UIKit.h> #import "JHSPullToRefreshProtocols.h" @class JHSMagicLampPullToRefreshView; @interface JHSCartoonPullToRefreshView : UIView<JHSPullToRefreshViewObject> { UIImageView *_sellingPointsView; JHSMagicLampPullToRefreshView *_lampView; UIImageView *_cartoonView; CGFloat _value; } /** * `用户下拉`时,左侧卖点露出的`最大`比例,大于等于1.0表示完全露出 */ @property(nonatomic, readonly) CGFloat value; @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PullToRefresh/JHSCartoonPullToRefreshView.m
Objective-C
// // JHSCartoonPullToRefreshView.m // JU // // Created by lamo on 14/12/23. // Copyright (c) 2014年 ju.taobao.com. All rights reserved. // #import "JHSCartoonPullToRefreshView.h" #import "JHSMagicLampPullToRefreshView.h" @implementation JHSCartoonPullToRefreshView @dynamic ready; @dynamic loading; @dynamic minDraggingDistance; - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.clipsToBounds = YES; _sellingPointsView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"JHSKit.bundle/selling_points"]]; _cartoonView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"JHSKit.bundle/katong_ju_0"]]; _cartoonView.contentMode = UIViewContentModeCenter; _lampView = [[JHSMagicLampPullToRefreshView alloc] init]; [self addSubview:_lampView]; [self addSubview:_sellingPointsView]; [self addSubview:_cartoonView]; } return self; } - (id)forwardingTargetForSelector:(SEL)aSelector { return _lampView; } - (void)layoutWithPresenterState:(id<JHSPullToRefreshPresenter>)state { _lampView.frame = self.bounds; [_lampView layoutWithPresenterState:state]; CGFloat offsetY = state.visibleHeight; CGFloat w = self.bounds.size.width; CGFloat centerX[2] = { w / 6.0, w / 6.0 * 5.0, }; _sellingPointsView.center = CGPointMake( centerX[0], self.bounds.size.height - _sellingPointsView.bounds.size.height / 2.0); _cartoonView.center = CGPointMake(centerX[1], self.bounds.size.height + 138.0 - _cartoonView.bounds.size.height / 2.0 - offsetY * 1.6); if (!state.dragging) { return; } _value = MAX(state.visibleHeight / (CGRectGetHeight(_sellingPointsView.bounds)), _value); if (offsetY < 80.0) { _cartoonView.image = [UIImage imageNamed:@"JHSKit.bundle/katong_ju_0"]; } else if (offsetY < 128.0) { _cartoonView.image = [UIImage imageNamed:@"JHSKit.bundle/katong_ju_1"]; } else { _cartoonView.image = [UIImage imageNamed:@"JHSKit.bundle/katong_ju_2"]; } } - (CGFloat)value { return _value; } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PullToRefresh/JHSMagicLampPullToRefreshView.h
C/C++ Header
// // JHSMagicLampPullToRefreshView.h // JU // // Created by lamo on 14/12/23. // Copyright (c) 2014年 ju.taobao.com. All rights reserved. // #import <UIKit/UIKit.h> #import "JHSPullToRefreshProtocols.h" @interface JHSMagicLampPullToRefreshView : UIView<JHSPullToRefreshViewObject> { UIImageView *_lampView; UIImageView *_circleView; UIImageView *_textView; CABasicAnimation *_storedAnimation; // 从view hierarchy移除时,保存正在执行的动画 } @property(nonatomic, assign) BOOL ready; @property(nonatomic, assign) BOOL loading; @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PullToRefresh/JHSMagicLampPullToRefreshView.m
Objective-C
// // JHSMagicLampPullToRefreshView.m // JU // // Created by lamo on 14/12/23. // Copyright (c) 2014年 ju.taobao.com. All rights reserved. // #import "JHSMagicLampPullToRefreshView.h" #import "UIView+SNEdge.h" #import "POP.h" @implementation JHSMagicLampPullToRefreshView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.clipsToBounds = YES; _lampView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"JHSKit.bundle/magic_lamp"]]; _circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"JHSKit.bundle/circle_around_lamp"]]; _textView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"JHSKit.bundle/slogon_text"]]; _circleView.alpha = .0; [self addSubview:_lampView]; [self addSubview:_circleView]; [self addSubview:_textView]; } return self; } - (CGFloat)minDraggingDistance { return 72.0; } - (void)setReady:(BOOL)ready { if (_ready == ready) { return; } _ready = ready; /* * 8c9aba 和之前使用Core Animation实现,根据Core Animation特性, * 隐藏/显示动画不会跟随布局的改变(layoutWithPresenterState:)而移动 * 所以改为使用Pop实现 * * Core * Animation会直接修改CALayer对象的值,而动画则在提交后交给单独线程/进程执行,后续的布局改动不会对动画线程/进程造成影响 * 这样的好处是CALayer对象的属性/方法可以真实地反映对象的状态,与逻辑统一 * 比如之前的实现中可以移除_ready成员变量,直接读写_circleView.layer.hidden * * 坏处是返回的值与看到的效果不统一,CALayer的presentationLayer属性的对象反映当前显示的状态 * pop框架会真实地修改对象的属性 */ POPBasicAnimation *animation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha]; animation.duration = .15; animation.fromValue = @(_ready ? .0 : 1.0); animation.toValue = @(_ready ? 1.0 : .0); [_circleView pop_addAnimation:animation forKey:@"hidingAnimation"]; } #define kSecondsPerCircle (1.0) #define kKeyPathRotationZ @"transform.rotation.z" #define kAnimationKeyRotation @"RotationAnimation" - (void)setLoading:(BOOL)loading { if (_loading == loading) { return; } _loading = loading; if (_loading) { CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:kKeyPathRotationZ]; a.beginTime = [_circleView.layer convertTime:CACurrentMediaTime() fromLayer:nil]; a.toValue = @(M_PI * 2.0); a.duration = kSecondsPerCircle; a.repeatCount = CGFLOAT_MAX; [_circleView.layer addAnimation:a forKey:kAnimationKeyRotation]; } else { CALayer *presentationLayer = (CALayer *)_circleView.layer.presentationLayer; CGFloat angle = [[presentationLayer valueForKeyPath:kKeyPathRotationZ] floatValue]; if (angle != .0) { angle = angle < .0 ? (M_PI * 2.0 + angle) : angle; CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:kKeyPathRotationZ]; a.fromValue = @(angle); a.toValue = @(M_PI * 2.0); a.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; a.duration = kSecondsPerCircle * (1.0 - angle / (M_PI * 2.0)) * .6; [_circleView.layer addAnimation:a forKey:kAnimationKeyRotation]; } else { [_circleView.layer removeAnimationForKey:kAnimationKeyRotation]; } } } // CA框架中的动画,layer移出hierarchy后被删除,需要在view加回window后重新添加 // 第一次添加动画时应该显式设置animation实例的beginTime属性,并且在之后保持不变,这样恢复后就像没有停止过一样 - (void)willMoveToWindow:(UIWindow *)newWindow { [super willMoveToWindow:newWindow]; if (newWindow) { return; } if (!_loading) { return; } _storedAnimation = [[_circleView.layer animationForKey:kAnimationKeyRotation] copy]; } - (void)didMoveToWindow { [super didMoveToWindow]; if (!self.window) { return; } if (!_loading) { _storedAnimation = nil; return; } [_circleView.layer addAnimation:_storedAnimation forKey:kAnimationKeyRotation]; _storedAnimation = nil; } - (void)layoutWithPresenterState:(id<JHSPullToRefreshPresenter>)state { _circleView.center = CGPointMake(self.sn_width / 2.0, self.sn_height - state.visibleHeight + _circleView.sn_height / 2.0 + 5.0); _lampView.center = _circleView.center; _textView.center = CGPointMake(self.bounds.size.width / 2.0, _circleView.sn_bottom + 5.0 + _textView.sn_height / 2.0); } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PullToRefresh/JHSPullToRefreshControl.h
C/C++ Header
// // JHSPullToRefreshView.h // PTR // // Created by lamo on 14/12/18. // Copyright (c) 2014年 juhuasuan. All rights reserved. // #import <UIKit/UIKit.h> #import "JHSPullToRefreshProtocols.h" @interface JHSPullToRefreshControl : UIControl<JHSPullToRefreshPresenter> { BOOL _dragging, _layoutManually; UIView<JHSPullToRefreshViewObject> *_view; CFTimeInterval _beginDraggingTime, _beginLoadingTime; } @property(nonatomic, readonly) BOOL refreshing; @property(nonatomic, assign) BOOL dragging; @property(nonatomic, assign) JHSPullToRefreshPosition position; @property(nonatomic, assign) BOOL alwaysOnTop; @property(nonatomic, strong) UIView<JHSPullToRefreshViewObject> *view; /** * 如果view实现value方法,直接返回;否则返回0.0 */ @property(nonatomic, readonly) CGFloat value; @property(nonatomic, readonly) CFTimeInterval beginDraggingTime; @property(nonatomic, readonly) CFTimeInterval beginLoadingTime; /** * 是否下拉结束后马上发送actions,默认为NO * 值为YES时,动画中只会恢复contentOffset而不会修改contentInset */ @property(nonatomic, assign) BOOL sendsActionsImmediately; /** * 是否自动布局,默认值为NO * 为NO时,内部会基于KVO等机制自动获取需要的状态:dragging 和 contentOffset; * 也可以设为YES,手动调用 scrollViewDidScrolled 和 scrollViewDidEndDragging。 */ @property(nonatomic, assign) BOOL layoutManually; - (void)scrollViewDidScrolled; - (void)scrollViewDidEndDragging; /** * 不提供start接口,因为代码控制的开始下拉刷新不是好的交互方式 */ - (void)endRefreshing; - (void)beginRefreshing; @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PullToRefresh/JHSPullToRefreshControl.m
Objective-C
// // JHSPullToRefreshView.m // PTR // // Created by lamo on 14/12/18. // Copyright (c) 2014年 juhuasuan. All rights reserved. // #import "JHSPullToRefreshControl.h" #import "JHSMagicLampPullToRefreshView.h" #define KEY_PATH_CONTENT_OFFSET @"contentOffset" /// OC类型的类型转换,_c_是要转换的类名,不可以为空 #define JHSObjectConvert(_c_, _o_) \ ({ \ NSObject* o = (_o_); \ if (o != nil) { \ if (!o || ![o isKindOfClass:[_c_ class]]) { \ o = nil; \ } \ } \ (_c_*) o; \ }) //_handler_不应该被执行,但是需要通过语法检查,避免在非DEBUG模式下因为语法问题编译不通过 #define JHSAssert(_condition_, _handler_) \ do { \ assert(!!(_condition_)); \ if (NO) { \ _handler_; \ } \ } while (0) @interface JHSPullToRefreshControl () @property(nonatomic, assign) CFTimeInterval beginDraggingTime; @property(nonatomic, assign) CFTimeInterval beginLoadingTime; @end @implementation JHSPullToRefreshControl - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.view = [JHSMagicLampPullToRefreshView new]; } return self; } - (IBAction)scrollViewPanned:(UIPanGestureRecognizer *)sender { if (_layoutManually) { return; } BOOL dragging = !(sender.state == UIGestureRecognizerStateCancelled || sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateFailed); [self scrollViewDraggingStateChanged:dragging]; } - (void)willMoveToSuperview:(UIView *)newSuperview { [super willMoveToSuperview:newSuperview]; UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); if (!scrollView) { return; } [scrollView removeObserver:self forKeyPath:KEY_PATH_CONTENT_OFFSET]; [scrollView.panGestureRecognizer removeTarget:self action:@selector(scrollViewPanned:)]; } - (void)didMoveToSuperview { [super didMoveToSuperview]; UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); if (!scrollView) { return; } [scrollView addObserver:self forKeyPath:KEY_PATH_CONTENT_OFFSET options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL]; [scrollView.panGestureRecognizer addTarget:self action:@selector(scrollViewPanned:)]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (_layoutManually) { return; } if ([change[NSKeyValueChangeNewKey] isEqual:change[NSKeyValueChangeOldKey]]) { return; } UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); JHSAssert(scrollView != nil, return ); [self scrollViewContentOffsetChanged]; } - (CGFloat)value { if (!_view || ![_view respondsToSelector:@selector(value)]) { return .0; } return _view.value; } - (BOOL)refreshing { return _view.loading; } - (void)setRefreshing:(BOOL)refreshing { if (_view.loading == refreshing) { return; } UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); if (!scrollView) { return; } _view.loading = refreshing; BOOL immediate = self.sendsActionsImmediately; if (immediate && refreshing) { return; } // refreshing == YES时,延长duration和在completion中sendAction 有效防止抖动 // 0.6秒很重要 古伦一级棒 CFTimeInterval duration = refreshing ? .6 : .3; __weak typeof(self) weakSelf = self; __weak typeof(scrollView) weakScrollView = scrollView; if (immediate && refreshing) { self.beginLoadingTime = CACurrentMediaTime(); [self sendActionsForControlEvents:UIControlEventValueChanged]; } UIEdgeInsets inset; CGPoint offset; if (immediate) { offset = scrollView.contentOffset; if (self.position == kJHSPullToRefreshPositionTop) { offset.y = -scrollView.contentInset.top; } else { offset.y = scrollView.contentSize.height + scrollView.contentInset.bottom - CGRectGetHeight(scrollView.bounds); } } else { inset = scrollView.contentInset; CGFloat diff = _view.loading ? _view.minDraggingDistance : -_view.minDraggingDistance; if (self.position == kJHSPullToRefreshPositionTop) { inset.top += diff; } else { inset.bottom += diff; } } [UIView animateWithDuration:duration animations:^(void) { if (immediate) { weakScrollView.contentOffset = offset; } else { weakScrollView.contentInset = inset; } } completion:^(BOOL finished) { if (!weakSelf || !refreshing || immediate) { return; } weakSelf.beginLoadingTime = CACurrentMediaTime(); [weakSelf sendActionsForControlEvents:UIControlEventValueChanged]; }]; } - (void)setLayoutManually:(BOOL)layoutManually { if (layoutManually == _layoutManually) { return; } _layoutManually = layoutManually; [_view layoutWithPresenterState:self]; } - (void)scrollViewDidScrolled { JHSAssert(_layoutManually, return ); UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); if (!scrollView) { return; } [self scrollViewDraggingStateChanged:YES]; [self scrollViewContentOffsetChanged]; } - (void)scrollViewDidEndDragging { JHSAssert(_layoutManually, return ); UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); if (!scrollView) { return; } [self scrollViewDraggingStateChanged:NO]; } - (void)endRefreshing { self.refreshing = NO; } - (void)beginRefreshing { self.refreshing = YES; } - (void)scrollViewContentOffsetChanged { if (!_view.loading) { UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); JHSAssert(scrollView != nil, return ); CGFloat offsetY = .0; if (self.position == kJHSPullToRefreshPositionTop) { offsetY = -scrollView.contentOffset.y - scrollView.contentInset.top; } else { offsetY = scrollView.contentOffset.y + CGRectGetHeight(self.bounds) - scrollView.contentSize.height - scrollView.contentInset.bottom; } _view.ready = offsetY >= _view.minDraggingDistance; } [_view layoutWithPresenterState:self]; } - (void)scrollViewDraggingStateChanged:(BOOL)dragging { if (_dragging == dragging) { return; } _dragging = dragging; if (_dragging) { _beginDraggingTime = CACurrentMediaTime(); } else if (!_view.loading && _view.ready) { self.refreshing = YES; } } - (void)layoutSubviews { [super layoutSubviews]; UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); _view.frame = CGRectMake(0, 64, CGRectGetWidth(scrollView.frame), CGRectGetHeight(scrollView.frame)); [_view layoutWithPresenterState:self]; } - (CGFloat)visibleHeight { UIScrollView *scrollView = JHSObjectConvert(UIScrollView, self.superview); if (!scrollView) { return .0; } CGFloat h = .0; if (self.position == kJHSPullToRefreshPositionTop) { h = -scrollView.contentOffset.y - scrollView.contentInset.top; } else { h = scrollView.contentOffset.y + CGRectGetHeight(self.bounds) - scrollView.contentSize.height - scrollView.contentInset.bottom; } if (_view.loading) { h += _view.minDraggingDistance; } return h; } - (void)setView:(UIView<JHSPullToRefreshViewObject> *)view { if (_view == view) { return; } [_view removeFromSuperview]; [self addSubview:view]; _view = view; } @end
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay
ios/Classes/PullToRefresh/JHSPullToRefreshProtocols.h
C/C++ Header
// // JHSPullToRefreshProtocols.h // JU // // Created by lamo on 14/12/23. // Copyright (c) 2014年 ju.taobao.com. All rights reserved. // #ifndef JU_JHSPullToRefreshProtocols_h #define JU_JHSPullToRefreshProtocols_h #import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, JHSPullToRefreshPosition) { kJHSPullToRefreshPositionTop, kJHSPullToRefreshPositionBottom }; @protocol JHSPullToRefreshViewObject; @protocol JHSPullToRefreshPresenter @property(nonatomic, readonly) BOOL dragging; @property(nonatomic, readonly) CGFloat visibleHeight; @property(nonatomic, readonly) JHSPullToRefreshPosition position; @property(nonatomic, readonly) BOOL alwaysOnTop; @property(nonatomic, strong) UIView<JHSPullToRefreshViewObject> *view; @end @protocol JHSPullToRefreshViewObject @property(nonatomic, assign) BOOL ready; @property(nonatomic, assign) BOOL loading; @property(nonatomic, readonly) CGFloat minDraggingDistance; - (void)layoutWithPresenterState:(id<JHSPullToRefreshPresenter>)state; @optional /** * 控件值,由实现定义其实际意义 */ @property(nonatomic, readonly) CGFloat value; @end #endif
xiekw2010/Cnodejs-React-Native
0
Yet another client for https://cnodejs.org/ building on react-native
Objective-C
xiekw2010
David Tse
Alipay