@nstudio/nativescript-coachmarks
在 NativeScript 的现有 UI 上使用形状剪裁显示用户教练标记。
npm i --save @nstudio/nativescript-coachmarks
- 版本: 4.0.0
- GitHub: https://github.com/nstudio/nativescript-ui-kit
- NPM: https://npmjs.net.cn/package/%40nstudio%2Fnativescript-coachmarks
- 下载
- 昨天: 0
- 上周: 0
- 上个月: 0
NativeScript 插件,用于在现有 UI 上通过形状剪裁显示用户教练标记。此方法利用您的实际 UI 作为用户入门过程的一部分。
基于 MPCoachMarks。
您可以在此处查看截图。
安装
npm install @nstudio/nativescript-coachmarks --save
用法
Android
import { CoachMarks, CoachMark } from '@nstudio/nativescript-coachmarks';
// assuming page is defined
let AndroidButton = page.getViewById('my-button')
let AndroidLabel = page.getViewById('my-label');
let cm = new CoachMarks();
cm.initEvents(); //If you want events
cm.events.on('click', (eventData) => {
// clicked on item at step index: eventData.data.index
});
cm.events.on('cleanup', (eventData) => {
// clean up any instances in your implementation
});
cm.events.on('navigate', (eventData) => {
// navigated to index
});
let marks = [
new CoachMark({
caption: '1. My Button.',
view: AndroidButton
}),
new CoachMark({
caption: '2. My Label.',
view: AndroidLabel
})
];
cm.start(marks);
简单
使用静态方法显示教练标记。
import { CoachMarks, CoachMark } from '@nstudio/nativescript-coachmarks';
// assuming page is defined
let iOSButton = page.getViewById('my-button').ios;
let iOSLabel = page.getViewById('my-label').ios;
let marks = [
new CoachMark({
position: CGRectMake(
iOSButton.frame.origin.x - 5,
iOSButton.frame.origin.y + 20,
iOSButton.frame.size.width + 10,
iOSButton.frame.size.height
),
caption: '1. My Button.',
shape: CoachMark.SHAPES.DEFAULT,
labelPosition: CoachMark.LABEL_POSITIONS.BOTTOM,
labelAlignment: CoachMark.LABEL_ALIGNMENTS.LEFT,
showArrow: true
}),
new CoachMark({
position: CGRectMake(
iOSLabel.frame.origin.x,
iOSLabel.frame.origin.y + 64,
iOSLabel.frame.size.width,
iOSLabel.frame.size.height
),
caption: '2. My Label.',
shape: CoachMark.SHAPES.DEFAULT,
labelPosition: CoachMark.LABEL_POSITIONS.BOTTOM,
labelAlignment: CoachMark.LABEL_ALIGNMENTS.CENTER,
showArrow: true
})
];
CoachMarks.start(marks);
高级
通过创建一个事件监听器实例来配置高级选项,进一步自定义教练标记。
import { CoachMarks, CoachMark, ICoachMarkOptions } from '@nstudio/nativescript-coachmarks';
// define custom options
let options: ICoachMarkOptions = {
continueLabelText: 'Tap Screen for Next Tip',
skipButtonText: 'Exit',
lblSpacing: 15,
maskColor: UIColor.colorWithRedGreenBlueAlpha(0.30, 0.46, 0.89, .9)
};
// create a CoachMarks instance
let coachMarksInstance = new CoachMarks();
// initialize events
coachMarksInstance.initEvents();
// wire up events
// fired each time user taps screen and advances to next step (including the first step display)
coachMarksInstance.events.on('navigate', (eventData) => {
console.log(`navigated to index: ${eventData.data.index}`);
// customize 'continue' label or 'skip' button
// their style can be changed upon each step or only once on first step
// first, grab the coachmarks instance
let instance = eventData.data.instance;
// wanna change the arrow image for each step?
instance.arrowImage.image = UIImage.imageNamed('custom-arrow.png');
if (instance.lblContinue) {
// customize continue button
// only available when the first step fires (disappears after first tap)
let labelContinue = instance.lblContinue.frame;
instance.lblContinue.frame = CGRectMake(labelContinue.origin.x, labelContinue.origin.y - 20, labelContinue.size.width, labelContinue.size.height + 20);
instance.lblContinue.backgroundColor = new Color('#FFE108').ios;
// custom caption color
instance.lblCaption.textColor = new Color('#FFE108').ios;
// customize skip button
let btnSkip = instance.btnSkipCoach.frame;
instance.btnSkipCoach.frame = CGRectMake(btnSkip.origin.x, btnSkip.origin.y - 20, btnSkip.size.width, btnSkip.size.height + 20);
}
});
coachMarksInstance.events.on('click', (eventData) => {
// clicked on item at step index: eventData.data.index
});
coachMarksInstance.events.on('cleanup', (eventData) => {
// clean up any instances in your implementation
});
// define your marks
// assuming page is defined
let iOSButton = page.getViewById('my-button').ios;
let iOSLabel = page.getViewById('my-label').ios;
let marks = [
new CoachMark({
position: CGRectMake(
iOSButton.frame.origin.x - 5,
iOSButton.frame.origin.y + 20,
iOSButton.frame.size.width + 10,
iOSButton.frame.size.height
),
caption: '1. My Button.',
shape: CoachMark.SHAPES.DEFAULT,
labelPosition: CoachMark.LABEL_POSITIONS.BOTTOM,
labelAlignment: CoachMark.LABEL_ALIGNMENTS.LEFT,
showArrow: true
}),
new CoachMark({
position: CGRectMake(
iOSLabel.frame.origin.x,
iOSLabel.frame.origin.y + 64,
iOSLabel.frame.size.width,
iOSLabel.frame.size.height
),
caption: '2. My Label.',
shape: CoachMark.SHAPES.DEFAULT,
labelPosition: CoachMark.LABEL_POSITIONS.BOTTOM,
labelAlignment: CoachMark.LABEL_ALIGNMENTS.CENTER,
showArrow: true
})
];
CoachMarks.start(marks, options, coachMarksInstance);
教练标记
用于配置和显示教练标记。
属性
属性 | 描述 |
---|---|
CoachMarks.APP_SETTINGS_KEY: string |
保存您的标记是否已显示时使用的持久化键。默认为 'CoachMarks'。 |
CoachMarks.DEBUG: boolean |
如果您在设置过程中遇到问题,则开启一些有用的日志记录。 |
CoachMarks.CONTINUE_LOCATIONS: ICONTINUE_LOCATION |
与 continueLocation 选项一起使用,以更改继续/跳过栏的位置。支持:TOP、CENTER、BOTTOM。 |
events: Observable |
设置实例事件时使用。 |
方法
方法 | 描述 |
---|---|
CoachMarks.start(marks: Array |
用于启动教练标记。 |
CoachMarks.HAS_SHOWN(): boolean |
教练标记是否已显示。 |
CoachMarks.PERSIST(): void |
简单地使用 CoachMarks.APP_SETTINGS_KEY 持久化 true 。您通常不会直接使用此功能,而是在调用 start 时使用 persist 选项时内部使用。 |
CoachMarks.RESET(): void |
用于清除已显示标记的持久化值。 |
选项
interface ICoachMarkOptions {
enableContinueLabel?: boolean; // true
enableSkipButton?: boolean; // true
continueLabelText?: string; // 'Tap to continue'
skipButtonText?: string; // 'Skip'
animationDuration?: number; // .3
continueLocation?: number; // Bottom
lblSpacing?: number; // 35
cutoutRadius?: number; // 2
maskColor?: any; // 0,0,0 alpha 0.9
maxLblWidth?: number; // 230
persist?: boolean; // false
}
CoachMark
用于定义您的标记。
属性
属性 | 描述 |
---|---|
position: any |
一个 iOS CGRect 位置对象。 |
caption: string |
您的标题标签文本。 |
shape: number |
使用 CoachMark.SHAPES 。支持:TOP、CENTER、BOTTOM。 |
labelPosition: number |
使用 CoachMark.LABEL_POSITIONS 。支持:BOTTOM、LEFT、TOP、RIGHT、RIGHT_BOTTOM。 |
labelAlignment: number |
使用 CoachMark.LABEL_ALIGNMENTS 。支持:CENTER、LEFT、RIGHT。 |
showArrow: boolean |
显示箭头或不显示。 |
closeOnCutOutTap?: boolean; |
当点击任何剪裁时,完全关闭教练标记会话。默认为 false。 |
view:View |
用于高亮的视图。仅限 Android。 |
许可
MIT