Merge pull request #2867 from umbrellaPP/next

check whether has editBox module in jsb
This commit is contained in:
pandamicro
2018-06-16 18:23:28 +08:00
committed by GitHub
+179 -172
View File
@@ -22,192 +22,199 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let KeyboardReturnType = cc.EditBox.KeyboardReturnType;
let InputMode = cc.EditBox.InputMode;
let InputFlag = cc.EditBox.InputFlag;
let _p = cc.EditBox._EditBoxImpl.prototype;
function getInputType(type) {
switch (type) {
case InputMode.EMAIL_ADDR:
return 'email';
case InputMode.NUMERIC:
case InputMode.DECIMAL:
return 'number';
case InputMode.PHONE_NUMBER:
return 'phone';
case InputMode.URL:
return 'url';
case InputMode.SINGLE_LINE:
case InputMode.ANY:
default:
return 'text';
}
}
function getKeyboardReturnType (type) {
switch (type) {
case KeyboardReturnType.DEFAULT:
case KeyboardReturnType.DONE:
return 'done';
case KeyboardReturnType.SEND:
return 'send';
case KeyboardReturnType.SEARCH:
return 'search';
case KeyboardReturnType.GO:
return 'go';
case KeyboardReturnType.NEXT:
return 'next';
}
return 'done';
}
function updateLabelsInvisible (editBox) {
let placeholderLabel = editBox._placeholderLabel;
let textLabel = editBox._textLabel;
let displayText = editBox._impl._text;
placeholderLabel.node.active = displayText === '';
textLabel.node.active = displayText !== '';
}
_p.createInput = function() {
let editBoxImpl = this;
let multiline = this._inputMode === InputMode.ANY;
let inputTypeString = getInputType(editBoxImpl._inputMode);
if (editBoxImpl._inputFlag === InputFlag.PASSWORD)
inputTypeString = 'password';
jsb.inputBox.show({
defaultValue: editBoxImpl._text,
maxLength: editBoxImpl._maxLength,
multiple: multiline,
confirmHold: false,
confirmType: getKeyboardReturnType(editBoxImpl._returnType),
inputType: inputTypeString
});
if (this._delegate) {
let editBox = this._delegate;
cc.Component.EventHandler.emitEvents(editBox.editingDidBegan, editBox);
editBox.node.emit('editing-did-began', editBox);
updateLabelsInvisible(editBox);
(function () {
if (!(cc && cc.EditBox)) {
return;
}
let KeyboardReturnType = cc.EditBox.KeyboardReturnType;
let InputMode = cc.EditBox.InputMode;
let InputFlag = cc.EditBox.InputFlag;
let _p = cc.EditBox._EditBoxImpl.prototype;
function onConfirm(res) {
editBoxImpl._delegate && editBoxImpl._delegate.editBoxEditingReturn && editBoxImpl._delegate.editBoxEditingReturn();
}
jsb.inputBox.onConfirm(onConfirm);
function onInput(res) {
if (res.value.length > editBoxImpl._maxLength) {
res.value = res.value.slice(0, editBoxImpl._maxLength);
function getInputType(type) {
switch (type) {
case InputMode.EMAIL_ADDR:
return 'email';
case InputMode.NUMERIC:
case InputMode.DECIMAL:
return 'number';
case InputMode.PHONE_NUMBER:
return 'phone';
case InputMode.URL:
return 'url';
case InputMode.SINGLE_LINE:
case InputMode.ANY:
default:
return 'text';
}
if (editBoxImpl._delegate && editBoxImpl._delegate.editBoxTextChanged) {
if (editBoxImpl._text !== res.value) {
editBoxImpl._text = res.value;
editBoxImpl._delegate.editBoxTextChanged(editBoxImpl._text);
}
function getKeyboardReturnType (type) {
switch (type) {
case KeyboardReturnType.DEFAULT:
case KeyboardReturnType.DONE:
return 'done';
case KeyboardReturnType.SEND:
return 'send';
case KeyboardReturnType.SEARCH:
return 'search';
case KeyboardReturnType.GO:
return 'go';
case KeyboardReturnType.NEXT:
return 'next';
}
return 'done';
}
function updateLabelsInvisible (editBox) {
let placeholderLabel = editBox._placeholderLabel;
let textLabel = editBox._textLabel;
let displayText = editBox._impl._text;
placeholderLabel.node.active = displayText === '';
textLabel.node.active = displayText !== '';
}
_p.createInput = function() {
let editBoxImpl = this;
let multiline = this._inputMode === InputMode.ANY;
let inputTypeString = getInputType(editBoxImpl._inputMode);
if (editBoxImpl._inputFlag === InputFlag.PASSWORD)
inputTypeString = 'password';
jsb.inputBox.show({
defaultValue: editBoxImpl._text,
maxLength: editBoxImpl._maxLength,
multiple: multiline,
confirmHold: false,
confirmType: getKeyboardReturnType(editBoxImpl._returnType),
inputType: inputTypeString
});
if (this._delegate) {
let editBox = this._delegate;
cc.Component.EventHandler.emitEvents(editBox.editingDidBegan, editBox);
editBox.node.emit('editing-did-began', editBox);
updateLabelsInvisible(editBox);
}
function onConfirm(res) {
editBoxImpl._delegate && editBoxImpl._delegate.editBoxEditingReturn && editBoxImpl._delegate.editBoxEditingReturn();
}
jsb.inputBox.onConfirm(onConfirm);
function onInput(res) {
if (res.value.length > editBoxImpl._maxLength) {
res.value = res.value.slice(0, editBoxImpl._maxLength);
}
if (editBoxImpl._delegate && editBoxImpl._delegate.editBoxTextChanged) {
if (editBoxImpl._text !== res.value) {
editBoxImpl._text = res.value;
editBoxImpl._delegate.editBoxTextChanged(editBoxImpl._text);
}
}
}
}
jsb.inputBox.onInput(onInput);
jsb.inputBox.onInput(onInput);
function onComplete(res) {
editBoxImpl._endEditing();
jsb.inputBox.offConfirm(onConfirm);
jsb.inputBox.offInput(onInput);
jsb.inputBox.offComplete(onComplete);
}
jsb.inputBox.onComplete(onComplete);
};
_p.setTabIndex = function (index) {
// jsb not support
};
_p.setFocus = function () {
// jsb not support
};
_p.isFocused = function () {
// jsb not support
},
_p.stayOnTop = function (flag) {
// jsb not support
};
_p._updateMatrix = function () {
// jsb not support
};
_p._updateSize = function (newWidth, newHeight) {
// jsb not support
};
_p.setMaxLength = function (maxLength) {
if (!isNaN(maxLength)) {
if(maxLength < 0) {
//we can't set Number.MAX_VALUE to input's maxLength property
//so we use a magic number here, it should works at most use cases.
maxLength = 65535;
function onComplete(res) {
editBoxImpl._endEditing();
jsb.inputBox.offConfirm(onConfirm);
jsb.inputBox.offInput(onInput);
jsb.inputBox.offComplete(onComplete);
}
this._maxLength = maxLength;
}
};
jsb.inputBox.onComplete(onComplete);
};
_p.setString = function (text) {
this._text = text;
this._updateInput();
updateLabelsInvisible(this._delegate);
};
_p.setTabIndex = function (index) {
// jsb not support
};
_p._updateInput = function () {
let tmpText = this._text;
if (this._inputFlag === InputFlag.PASSWORD) {
tmpText = tmpText.replace(/./g, '*');
}
this._delegate._textLabel.string = tmpText;
};
_p.setFocus = function () {
// jsb not support
};
_p.setFontSize = function (fontSize) {
this._edFontSize = fontSize || this._edFontSize;
this._delegate._textLabel.fontSize = this._edFontSize;
};
_p.isFocused = function () {
// jsb not support
},
_p.setFontColor = function (color) {
this._textColor = color;
this._delegate._textLabel.fontColor = this._textColor;
};
_p.stayOnTop = function (flag) {
// jsb not support
};
_p.setInputMode = function (inputMode) {
this._inputMode = inputMode;
};
_p._updateMatrix = function () {
// jsb not support
};
_p.setInputFlag = function (inputFlag) {
this._inputFlag = inputFlag;
};
_p._updateSize = function (newWidth, newHeight) {
// jsb not support
};
_p.setReturnType = function (returnType) {
this._returnType = returnType;
};
_p._onTouchEnded = function () {
this.createInput();
};
_p._endEditing = function () {
let self = this;
if (this._editing) {
self._endEditingOnMobile();
if (self._delegate && self._delegate.editBoxEditingDidEnded) {
self._delegate.editBoxEditingDidEnded();
_p.setMaxLength = function (maxLength) {
if (!isNaN(maxLength)) {
if(maxLength < 0) {
//we can't set Number.MAX_VALUE to input's maxLength property
//so we use a magic number here, it should works at most use cases.
maxLength = 65535;
}
this._maxLength = maxLength;
}
}
this._editing = false;
};
};
_p.clear = function () {
this._node = null;
this.setDelegate(null);
};
_p.setString = function (text) {
this._text = text;
this._updateInput();
updateLabelsInvisible(this._delegate);
};
_p._updateInput = function () {
let tmpText = this._text;
if (this._inputFlag === InputFlag.PASSWORD) {
tmpText = tmpText.replace(/./g, '*');
}
this._delegate._textLabel.string = tmpText;
};
_p.setFontSize = function (fontSize) {
this._edFontSize = fontSize || this._edFontSize;
this._delegate._textLabel.fontSize = this._edFontSize;
};
_p.setFontColor = function (color) {
this._textColor = color;
this._delegate._textLabel.fontColor = this._textColor;
};
_p.setInputMode = function (inputMode) {
this._inputMode = inputMode;
};
_p.setInputFlag = function (inputFlag) {
this._inputFlag = inputFlag;
};
_p.setReturnType = function (returnType) {
this._returnType = returnType;
};
_p._onTouchEnded = function () {
this.createInput();
};
_p._endEditing = function () {
let self = this;
if (this._editing) {
self._endEditingOnMobile();
if (self._delegate && self._delegate.editBoxEditingDidEnded) {
self._delegate.editBoxEditingDidEnded();
}
}
this._editing = false;
};
_p.clear = function () {
this._node = null;
this.setDelegate(null);
};
})();