-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
673a5cf
commit 62656a7
Showing
33 changed files
with
347 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ Thumbs.db | |
|
||
*.tgz | ||
packages/**/angular/dist | ||
*.aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
apps/demo-angular/src/plugin-demos/auto-fit-text.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<ActionBar title="auto-fit-text" class="action-bar"> </ActionBar> | ||
<GridLayout rows="*, *, *, *" columns="*" class="p-20"> | ||
<Label row="0" fontSize="36" text="This is a standard NS Label with textWrap enabled." textWrap="true"></Label> | ||
<AutoFitText row="1" text="Lorem Ipsum this is a long string of text that will shrink to fit this line." textWrap="false"></AutoFitText> | ||
<AutoFitText row="2" fontSize="48" text="Lorem Ipsum this line of text with fontSize ignored because the text is so long." textWrap="false"></AutoFitText> | ||
<AutoFitText row="3" text="Another line of AutoFitText" textWrap="false"></AutoFitText> | ||
</GridLayout> |
17 changes: 17 additions & 0 deletions
17
apps/demo-angular/src/plugin-demos/auto-fit-text.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component, NgZone } from '@angular/core'; | ||
import { DemoSharedAutoFitText } from '@demo/shared'; | ||
import { } from '@nativescript/auto-fit-text'; | ||
|
||
@Component({ | ||
selector: 'demo-auto-fit-text', | ||
templateUrl: 'auto-fit-text.component.html', | ||
}) | ||
export class AutoFitTextComponent { | ||
demoShared: DemoSharedAutoFitText; | ||
|
||
constructor(private _ngZone: NgZone) {} | ||
|
||
ngOnInit() { | ||
this.demoShared = new DemoSharedAutoFitText(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
apps/demo-angular/src/plugin-demos/auto-fit-text.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; | ||
import { NativeScriptAutoFitTextModule } from '@nativescript/auto-fit-text/angular'; | ||
import { AutoFitTextComponent } from './auto-fit-text.component'; | ||
|
||
@NgModule({ | ||
imports: [NativeScriptCommonModule, NativeScriptAutoFitTextModule, NativeScriptRouterModule.forChild([{ path: '', component: AutoFitTextComponent }])], | ||
declarations: [AutoFitTextComponent], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
}) | ||
export class AutoFitTextModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Observable, EventData, Page } from '@nativescript/core'; | ||
import { DemoSharedAutoFitText } from '@demo/shared'; | ||
import {} from '@nativescript/auto-fit-text'; | ||
|
||
export function navigatingTo(args: EventData) { | ||
const page = <Page>args.object; | ||
page.bindingContext = new DemoModel(); | ||
} | ||
|
||
export class DemoModel extends DemoSharedAutoFitText {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" | ||
xmlns:AFT="@nativescript/auto-fit-text" navigatingTo="navigatingTo" class="page"> | ||
<Page.actionBar> | ||
<ActionBar title="auto-fit-text" icon="" class="action-bar"> | ||
</ActionBar> | ||
</Page.actionBar> | ||
<GridLayout rows="*, *, *, *" columns="*" class="p-20"> | ||
<Label row="0" fontSize="36" text="This is a standard NS Label with textWrap enabled." textWrap="true"></Label> | ||
<AFT:AutoFitText row="1" text="Lorem Ipsum this is a long string of text that will shrink to fit this line." textWrap="false"></AFT:AutoFitText> | ||
<AFT:AutoFitText row="2" fontSize="48" text="Lorem Ipsum this line of text with fontSize ignored because the text is so long." textWrap="false"></AFT:AutoFitText> | ||
<AFT:AutoFitText row="3" text="Another line of AutoFitText" textWrap="false"></AFT:AutoFitText> | ||
</GridLayout> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,9 @@ | |
}, | ||
"social-share": { | ||
"tags": [] | ||
}, | ||
"auto-fit-text": { | ||
"tags": [] | ||
} | ||
}, | ||
"workspaceLayout": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Nativescript auto-fit-text | ||
|
||
```bash | ||
ns plugin add @nativescript/auto-fit-text | ||
``` | ||
|
||
This plugin is based on the Nativescript Label implementation but with changes to adjust the font size according of the label's width | ||
|
||
## Usage | ||
|
||
### Nativescript | ||
|
||
```xml | ||
<Page | ||
xmlns="http://schemas.nativescript.org/tns.xsd" | ||
loaded="pageLoaded" | ||
class="page" | ||
xmlns:AFT="@nativescript/auto-fit-text" | ||
> | ||
<StackLayout class="p-20"> | ||
<AFT:AutoFitText | ||
text="Testinggggggggggggggggg" | ||
textWrap="false" | ||
></AFT:AutoFitText> | ||
</StackLayout> | ||
</Page> | ||
``` | ||
|
||
### Angular NativeScript | ||
|
||
```typescript | ||
import { NativeScriptAutoFitTextModule } from '@nativescript/auto-fit-text/angular'; | ||
|
||
// Be sure to add the plugin module to your NgModule | ||
@NgModule({ | ||
imports: [NativeScriptAutoFitTextModule], | ||
}) | ||
``` | ||
|
||
```xml | ||
<AutoFitText row="2" fontSize="48" text="Lorem Ipsum this line of text with fontSize ignored because the text is so long." textWrap="false"></AutoFitText> | ||
``` | ||
|
||
## Credits | ||
|
||
[@grantland - android-autofittextview](https://github.com/grantland/android-autofittextview) | ||
|
||
## License | ||
|
||
Apache License Version 2.0, January 2004 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { registerElement } from '@nativescript/angular'; | ||
import { AutoFitText } from '@nativescript/auto-fit-text'; | ||
|
||
@NgModule() | ||
export class NativeScriptAutoFitTextModule {} | ||
|
||
registerElement('AutoFitText', () => AutoFitText); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "nativescript-auto-fit-text-angular", | ||
"ngPackage": { | ||
"lib": { | ||
"entryFile": "index.ts", | ||
"umdModuleIds": { | ||
"@nativescript/core": "ns-core", | ||
"@nativescript/angular": "ns-angular", | ||
"@nativescript/auto-fit-text": "ns-auto-fit-text" | ||
} | ||
}, | ||
"whitelistedNonPeerDependencies": [ | ||
"." | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../../node_modules/ng-packagr/lib/ts/conf/tsconfig.ngc.json", | ||
"compilerOptions": { | ||
"types": ["node"], | ||
"baseUrl": ".", | ||
"paths": { | ||
"@nativescript/auto-fit-text": ["../../../dist/packages/auto-fit-text"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Label } from '@nativescript/core'; | ||
|
||
declare var me: any; | ||
|
||
export class AutoFitText extends Label { | ||
public createNativeView(): Object { | ||
const textField: android.widget.TextView = super.createNativeView() as android.widget.TextView; | ||
textField.setMaxLines(1); | ||
textField.setSingleLine(); | ||
textField.setMaxHeight(200); | ||
textField.setTextSize(200); | ||
textField.setMinHeight(40); | ||
textField.setTextAlignment(android.widget.TextView.TEXT_ALIGNMENT_CENTER); | ||
|
||
me.grantland.widget.AutofitHelper.create(textField); | ||
return textField; | ||
} | ||
|
||
initNativeView(): void { | ||
this.nativeView.owner = this; | ||
super.initNativeView(); | ||
} | ||
|
||
disposeNativeView(): void { | ||
this.nativeView.owner = null; | ||
super.disposeNativeView(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Label } from '@nativescript/core'; | ||
export declare class AutoFitText extends Label { | ||
createNativeView(): Object; | ||
initNativeView(): void; | ||
disposeNativeView(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Label } from '@nativescript/core'; | ||
|
||
export class AutoFitText extends Label { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
initNativeView(): void { | ||
this.nativeView.owner = this; | ||
|
||
const label = this.ios as UILabel; | ||
// label.font = label.font.fontWithSize(40); | ||
label.adjustsFontSizeToFitWidth = true; | ||
label.textAlignment = NSTextAlignment.Natural; | ||
|
||
super.initNativeView(); | ||
} | ||
|
||
disposeNativeView(): void { | ||
// Remove reference from native view to this instance. | ||
this.nativeView.owner = null; | ||
|
||
// If you want to recycle nativeView and have modified the nativeView | ||
// without using Property or CssProperty (e.g. outside our property system - 'setNative' callbacks) | ||
// you have to reset it to its initial state here. | ||
super.disposeNativeView(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@nativescript/auto-fit-text", | ||
"version": "1.0.0", | ||
"description": "NativeScript plugin for a label that resizes on a single line to fit the screen.", | ||
"main": "index", | ||
"typings": "index.d.ts", | ||
"nativescript": { | ||
"platforms": { | ||
"ios": "7.0.0", | ||
"android": "7.0.0" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/NativeScript/plugins.git" | ||
}, | ||
"keywords": [ | ||
"NativeScript", | ||
"JavaScript", | ||
"TypeScript", | ||
"iOS", | ||
"Android", | ||
"auto-fit-text" | ||
], | ||
"author": { | ||
"name": "NativeScript", | ||
"email": "oss@nativescript.org" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/NativeScript/plugins/issues" | ||
}, | ||
"license": "Apache-2.0", | ||
"homepage": "https://github.com/NativeScript/plugins", | ||
"readmeFilename": "README.md", | ||
"bootstrapper": "@nativescript/plugin-seed" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* Include.gradle configuration: http://docs.nativescript.org/plugins/plugins#includegradle-specification */ | ||
|
||
android { | ||
|
||
} | ||
|
||
dependencies { | ||
compile 'me.grantland:autofittextview:0.2.+' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference path="../../references.d.ts" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"rootDir": "." | ||
}, | ||
"exclude": ["**/*.spec.ts", "angular"], | ||
"include": ["**/*.ts", "references.d.ts"] | ||
} |
Oops, something went wrong.