@nativescript-copilot/vue
Nativescript-Vue 应用之旅 & 展示
npm i --save @nativescript-copilot/vue

Nativescript Copilot

为您的 Nativescript 应用提供分步讲解!

Vue-Demo

灵感来源于优秀的 React Native Copilot 插件

Nativescript-Copilot 是一个组件,目前仅适用于 NativeScript-Vue。如果您想看到 Nativescript-Core 或 Nativescript-Angular 的实现,请提交一个 PR。

快速入门 - Vue

npm install --save @nativescript-copilot/vue

主入口点

import Copilot from '@nativescript-copilot/vue';
Vue.use(Copilot)

Nativescript-Vue 使用方法

这可以在逐页的基础上使用。导游的主要驱动方式是通过传递每个步骤的 ref。例如下面,我们在 Image 组件中有一个名为 step1ref

  <StackLayout col="0" verticalAlignment="bottom" horizontalAlignment="left">
<Image ref="step1" src="~/assets/logo.png" height="75%" width="75%" borderWidth="1"/>
</StackLayout>

您可以将多个 refs 组合起来创建一个导游。您需要创建一个对象数组,该数组包含特定页面的导游配置。例如

      this.steps = [
{
name: 'First',
text: 'here is some text',
order: 1,
target: this.$refs.step1.nativeView,
animated: true,
isFirstStep: true
},
{
name: 'Second',
text: 'here is some text with a rounded highlighted zone and padding',
order: 2,
target: this.$refs.step2.nativeView,
animated: true,
highlightBorderRadius: 10,
highlighPadding: 5,
},
{
name: 'Third',
text: 'here is some text that should hopefully be long enought to cause a wrap. What will happen if the text is too long. Find out!',
order: 3,
target: this.$refs.step3.nativeView,
animated: true
},
{
name: 'Fourth',
text: 'This has a veritcal offset of -5 which will push the step 5dp towards the top',
order: 4,
target: this.$refs.step4.nativeView,
animated: false,
verticalOffset: -5,
},
{
name: 'Fifth',
text: '',
order: 4,
target: this.$refs.step3.nativeView,
animated: false,
isCustom: true,
itemTemplate: '<Label text="This is a custom template!" color="green"/>',
customBackgroundColor: 'black',
customBorderRadius: '15',
numberAccentColor: 'white',
numberBackgroundColor: 'green',
customTooltipStyle: {
fontFamily: 'Avenir-Bold',
tooltipFontSize: 12,
tooltipTextColor: 'white',
buttonFontSize: 12,
accentColor: 'white'
},
customLabels: {
skip: 'Stop',
previous: 'Before',
next: 'Continue',
finish: 'Done'
}
},
{
name: 'Sixth',
text: 'This will darken the whole page and center the tool tip',
order: 4,
target: this.$refs.step4.nativeView,
animated: false,
darkenWholePage: true,
isLastStep: true
}
]

Step 对象中有几个配置项

名称 类型 描述
name 字符串 纯粹用于装饰/组织目的
text 字符串 要在工具提示中显示的描述性文本
order 数字 这是页面上导游的哪个步骤
target 字符串 您希望导游停止的具体组件。这必须采用 this.$refs.step1.nativeView 的格式,其中 step1 是实际 ref 的名称
animated 布尔型 默认为 true,但如果您不想步骤动画到下一个步骤,则设置此选项,它将跳到下一个位置而没有任何动画
verticalOffset 数字 在您需要垂直偏移步骤突出显示的区域时使用。这可以是正数或负数
isFirstStep 布尔型 用于告诉插件哪个步骤是第一个,这样它就会隐藏“上一个”按钮
isLastStep 布尔型 用于告诉插件哪个步骤是最后一个,这样它就会隐藏“下一个”按钮并显示“完成”按钮
isLastStep 布尔型 用于告诉插件哪个步骤是最后一个,这样它就会隐藏“下一个”按钮并显示“完成”按钮
darkenWholePage 布尔型 用于告诉插件如果步骤没有突出显示的值,则暗化整个屏幕,并将文本框垂直和水平居中
showNumber 布尔型 在不希望显示特定步骤的步骤号时使用
numberBackgroundColor 字符串 在希望特定步骤有自定义数字背景颜色的情况下使用
numberAccentColor 字符串 在希望特定步骤有自定义数字强调颜色的情况下使用
customBackgroundColor 字符串 在希望特定步骤有自定义背景工具提示颜色的情况下使用
customBorderRadius 字符串 在希望特定步骤的工具提示有自定义边框半径的情况下使用
highlightPadding 数字 在希望自定义突出显示区域的面罩的内边距的情况下使用
highlightBorderRadius 数字 在需要为特定步骤的遮罩高亮区域设置自定义边框半径的情况下使用 (警告:当使用边框半径时,由于本插件的工作方式,边框半径过高/设备边缘附近边框半径过高将导致IOS UI故障,建议减小边框半径) (注意:使用边框半径会减小高亮区域,使用填充来再次增加)
isCustom 布尔型 在需要自定义工具提示,并带有itemTemplate选项的情况下使用
itemTemplate 字符串 如果步骤上的自定义组件为true,则传入XML字符串值(事件和动态属性不工作)
customTooltipStyle 对象 在需要为特定步骤的工具提示设置自定义样式的情况下使用
customLabels 对象 在需要为特定步骤的工具提示设置自定义样式的情况下使用

然后,您将步骤配置传递给Copilot组件作为steps属性。在下面的示例中,我们使用计算属性来提供steps属性

  <Copilot
:steps="computedSteps"
:animationDuration="animationDuration"
:labels="labels"
:tooltipStyle="tooltipStyle"
:overlayColor="overlayColor"
:backgroundColor="backgroundColor"
:accentColor="accentColor"
ref="copilot"
/>

还可以将其他几个属性传递给Copilot组件。它们是

名称 类型 默认 描述
animationDuration 字符串 300 动画移动到下一个步骤所需的ms
labels 对象 { skip: '跳过', next: '下一步', previous: '上一步', finish: '完成' } 工具提示中用于在浏览步骤之间移动的四个按钮的名称。跳过将在任何步骤结束浏览,而完成将仅在最后一个步骤结束。
tooltipStyle 对象 { fontFamily: Avenir-Light, tooltipFontSize: 14, tooltipTextColor: 'black', buttonFontSize: 14, accentColor: 'green' } 用于控制工具提示的整体外观
overlayColor 字符串 rgba(0, 0, 0, 0.4) 用于控制覆盖颜色
numberBackgroundColor 字符串 白色 用于设置默认数字背景颜色
numberAccentColor 字符串 绿色 用于设置默认数字强调颜色
toolTipBackgroundColor 字符串 白色 用于设置默认工具提示背景颜色
toolTipBorderRadius 字符串 '3' 用于设置默认工具提示边框半径
highlightBorderRadius 数字 0 用于设置遮罩上的默认高亮边框半径 (警告:当使用边框半径时,由于本插件的工作方式,边框半径过高/设备边缘附近边框半径过高将导致IOS UI故障,建议减小边框半径) (注意:使用边框半径会减小高亮区域,使用填充来再次增加)
highlightPadding 数字 5 用于设置遮罩上的默认高亮填充

上述选项的初始化示例(以TypeScript完成)

private animationDuration: number = 300;
private androidStatusBarVisible: boolean = false;
private labels: object = {
skip: 'Skip',
previous: 'Previous',
next: 'Next',
finish: 'Finish'
};
private tooltipStyle: object = {
fontFamily: 'Avenir-Light',
tooltipFontSize: 14,
tooltipTextColor: 'black',
buttonFontSize: 14,
accentColor: 'green'
}
private overlayColor: string = 'rgba(0, 0, 0, 0.4)';
private numberAccentColor: string = 'green';
private numberBackgroundColor: string = 'white';
private toolTipBackgroundColor: string = 'white';
private toolTipBorderRadius: string = '3';
private highlightPadding: number = 5;
private highlightBorderRadius: number = 10;

Copilot组件会发出几个事件

名称 类型 描述
step-change 对象 当步骤向前或向后移动时发出,发出包含stepLeaving和stepArriving的对象
stop -- 当copilot停止时发出
start -- 当copilot启动时发出
not-ready -- 当copilot收到无效布局时发出
highlight-tap -- 当copilot的高亮区域被轻触时发出

您将调用从Copilot组件中选择的名称的事件。在下面的示例中,我们正在调用事件上的函数

  <Copilot
:steps="computedSteps"
@step-change="stepChanged"
@stop="copilotStopped"
@not-ready="copilotNotReady"
@start="copilotStarted"
@highlight-tap="copilotHighlightTap"
ref="copilot"
/>

要在一个特定的页面上开始浏览,您需要调用Copilot的start函数。一个例子是:this.$refs.copilot.start();

Vue演示项目

查看演示项目,该项目实现了一个简单的项目,并使用了许多上述选项中讨论的插件。